Last active
December 16, 2015 07:09
-
-
Save moskinson/5396749 to your computer and use it in GitHub Desktop.
DFP: Detect iframe bring Ads with creative to show or hide empty space for ads Div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/javascript'> | |
$(document).ready(function(){ | |
var checkIframe = setInterval(function bringSecondPhase(){ | |
if (iframeIsLoaded){ | |
clearInterval(checkIframe) | |
console.log("iframe loaded!") | |
iframeHasAdvertismentAndShowOrHide() | |
} | |
else{ | |
console.log("iframe checking...") | |
} | |
},1000) | |
function iframeIsLoaded(){ | |
var $iframe = $('#div-gpt-ad-AD_UNIT_NAME-1').find('iframe') | |
return $iframe.length > 0 | |
} | |
function iframeHasAdvertismentAndShowOrHide(){ | |
var $iframe = $('#div-gpt-ad-AD_UNIT_NAME-1').find('iframe') | |
if (iframeIsLoaded()){ | |
var $iframeBody = $iframe.contents().find('body') | |
if (typeof $iframeBody == "undefined" || $iframeBody.html() == ""){ | |
console.log("iframe empty!") | |
$iframe.width(0) | |
$iframe.height(0) | |
$('#advertismentSticker').hide() | |
} | |
else { | |
console.log("iframe with creative!") | |
$('#advertismentSticker').show() | |
} | |
} | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment