Detroy and Refresh ad
1. Destroy ad
-
Ad slots can be destroyed using gladsdk.destroyAdSlots().
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test NAM SDK</title>
<script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script>
<script>
window.gladsdk = window.gladsdk || { cmd: [] };
</script>
</head>
<body>
<div id="division"></div>
<button id="destroy">Destroy</button>
<script>
window.gladsdk.cmd.push(function () {
var adSlotInfo = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division',
};
var adSlot = window.gladsdk.defineAdSlot(adSlotInfo);
window.gladsdk.displayAd(adSlot);
});
document.getElementById('destroy').addEventListener('click', function () {
window.gladsdk.cmd.push(function () {
var adSlot = window.gladsdk.findAdSlot('division');
window.gladsdk.destroyAdSlots([adSlot]);
});
});
</script>
</body>
</html> -
If no arguments are passed to gladsdk.destroyAdSlots(), destroy all ad slots.
window.gladsdk.destroyAdSlots();
2. Refresh ad
-
Use gladsdk.refreshAdSlots() to destroy existing ad slots and request new ads. (Refresh ad)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test NAM SDK</title>
<script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script>
<script>
window.gladsdk = window.gladsdk || { cmd: [] };
</script>
</head>
<body>
<div id="division"></div>
<button id="refresh">Refresh</button>
<script>
window.gladsdk.cmd.push(function () {
var adSlotInfo = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division',
};
var adSlot = window.gladsdk.defineAdSlot(adSlotInfo);
window.gladsdk.displayAd(adSlot);
});
document.getElementById('refresh').addEventListener('click', function () {
window.gladsdk.cmd.push(function () {
var adSlot = window.gladsdk.findAdSlot('division');
window.gladsdk.refreshAdSlots([adSlot]);
});
});
</script>
</body>
</html> -
If no arguments are passed to gladsdk.refreshAdSlots(), refresh all ad slots.
window.gladsdk.refreshAdSlots();