Forum Moderators: open
When the popup window is closed the parent window still contains the ‘welcome’ message. However I’d like to have this page change automatically while the popup window is open to a ‘thanks for visiting’ page.
This way the viewer would see my 'thanks for visiting' message when they close thw popup window
I’ve been trying to write a simple script using “onload” in the popup window that would change the url in the parent window but I can’t get it to work.
Any suggestion, any help appreciated.
<body onload="if (window.opener && !window.opener.closed){window.opener.parent.location='thanks.html';}">
detected if a visitor is coming from a link other than the homepage
Tricky and getting fiddly. You could try the following:
<script>
function myPage_Load()
{
if (window.opener)
{//we have an opener window so try to load the thanks page
if (window.opener.closed)
{// the opener window has since closed - open a new one.
window.open('thanks.htm');
}
else
{// load the thanks page into the opening window
window.opener.top.location.href = 'thanks.htm';
}
}
else
{//we have no opener so redirect to home, use replace so as not to
//create a loop in the browser history
document.location.replace('myhomepage.htm');
}
}
</script><body onload="myPage_Load()">
You'll see that the code's getting a little bloated - it's up to you how far you go with it.