Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Iframe onload event only after an anchor onclick


birdbrain - 10:35 am on Oct 14, 2012 (gmt 0)


Hi there Rain Lover,


This amended code will work in IE8 and I have also fine tuned the code to alert once only. ;)

<script type="text/javascript">

function init(){
test=true;
document.getElementById('go').onclick=function(){
ifr=document.createElement('iframe');
ifr.setAttribute('src',this.href);
ifr.src=this.href; /* IE8 needs this */
ifr.setAttribute('id','iframe_a');

ifr.onload=function() {
if(test==true){ /* this ensures a one off alert */
alert('Thanks for the visit!');
test=false;
}
}
document.getElementById('iframe_a_container').appendChild(ifr);
return false;
}
}

window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);

</script>


birdbrain


Thread source:: http://www.webmasterworld.com/javascript/4507876.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com