I'm running into a problem when trying to use the following code. It runs perfectly in Firefox, Safari, Chrome, and IE 9+10, but causes the rest of my page to 'crash' when running in IE8. The console error I receive is 'type mismatch' and the debugger points to the IF statement line. I've been banging my head against the wall trying to figure it out, but to no avail. Does anyone have a clue as to what the heck is going on here?
function writeIframe11092()
{
alert("BEFORE");
document.write('<iframe style=\"position:absolute;left:-40000px;\" src=\"https://mydomain.com/images/close.gif\" ></iframe>');
alert("AFTER");
}
if (window.attachEvent)
window.attachEvent('onload', writeIframe11092() );
else if (window.addEventListener)
window.addEventListener('load', writeIframe11092(),false);
writeIframe11092()
calls the function and returns a value (undefined
in this case), and passes that value to attachEvent
.
writeIframe11092
is a variable representing the function itself, that's what you want to use here.
if (window.attachEvent){
window.attachEvent('onload', writeIframe11092);
}
else if (window.addEventListener){
window.addEventListener('load', writeIframe11092, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With