Javascript Close Browser or goto external site function
- by aaroninfidel
Hello, I've been trying to figure out how I can go about creating a javascript function that will only be called when a user is accessing an external site or closing the window to the current site they're on.
So far I've come up with this, any help is greatly appreciated.
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function getAd()
{
var myAds = new Array();
myAds[0] = "http://localhost/link1";
myAds[1] = "http://localhost/link2";
var randomAd = Math.floor(Math.random() * myAds.length);
return myAds[randomAd];
}
function confirmExit(){
alert(getAd());
return false;
}
</script>