christianbarkholt
05-29-2015, 11:41 PM
Hi there,
I'm trying to make a javaScript function that can alter a piece of HTML code based on whether an ad-blocker is detected.
I want to to modify the top margin of an iframe. To do so, I need to execute a function ( writeiframe() ) inside another function that is inside setTimeout(). This works well in Chrome, but for some reason I can't get it to work in IE.
I have posted the main javaScript code below. This is a link to the full code: http://kulsvierhytten.dk/iframe-adblock.html
I'm not quite used to dealing with javaScript, so any and all help will be greatly appreciated. :)
function detect()
{
//create a iframe. Append the iframe to the body. And then after 100ms check if their offsetHeight, display or visibility is set such a way that user cannot see them.
//In the URL use the words specific to advertising so that Adblock can do string matching.
var iframe = document.createElement("iframe");
iframe.height = "1px";
iframe.width = "1px";
iframe.id = "ads-text-iframe";
iframe.src = "http://domain.com/ads.html";
document.body.appendChild(iframe);
setTimeout(function()
{
var iframe = document.getElementById("ads-text-iframe");
if(iframe.style.display == "none" || iframe.style.display == "hidden" || iframe.style.visibility == "hidden" || iframe.offsetHeight == 0)
{
adBlock = "margin-top: -174px;";
alert(adBlock);
iframe.remove();
writeiframe();
}
else
{
adBlock = "margin-top: 0px;";
alert(adBlock);
iframe.remove();
writeiframe();
}
}, 100);
}
detect();
I'm trying to make a javaScript function that can alter a piece of HTML code based on whether an ad-blocker is detected.
I want to to modify the top margin of an iframe. To do so, I need to execute a function ( writeiframe() ) inside another function that is inside setTimeout(). This works well in Chrome, but for some reason I can't get it to work in IE.
I have posted the main javaScript code below. This is a link to the full code: http://kulsvierhytten.dk/iframe-adblock.html
I'm not quite used to dealing with javaScript, so any and all help will be greatly appreciated. :)
function detect()
{
//create a iframe. Append the iframe to the body. And then after 100ms check if their offsetHeight, display or visibility is set such a way that user cannot see them.
//In the URL use the words specific to advertising so that Adblock can do string matching.
var iframe = document.createElement("iframe");
iframe.height = "1px";
iframe.width = "1px";
iframe.id = "ads-text-iframe";
iframe.src = "http://domain.com/ads.html";
document.body.appendChild(iframe);
setTimeout(function()
{
var iframe = document.getElementById("ads-text-iframe");
if(iframe.style.display == "none" || iframe.style.display == "hidden" || iframe.style.visibility == "hidden" || iframe.offsetHeight == 0)
{
adBlock = "margin-top: -174px;";
alert(adBlock);
iframe.remove();
writeiframe();
}
else
{
adBlock = "margin-top: 0px;";
alert(adBlock);
iframe.remove();
writeiframe();
}
}, 100);
}
detect();