Welcome to WebmasterWorld Guest from 54.146.174.220

Forum Moderators: open

Javascript help

Changing the original window from a pop-up

   
10:36 pm on Jul 7, 2002 (gmt 0)

10+ Year Member



My website has a simple opening page the ‘Welcomes’ the viewer and has a link the launches a popup window in which the contents of the site can be viewed.

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.

1:18 am on Jul 8, 2002 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to the forum, flashmastermak. Try this:

<body onLoad="window.opener.parent.location='thanks.html'">

3:04 am on Jul 8, 2002 (gmt 0)

10+ Year Member



thanks tedster

It works perfectly

Mak

8:51 am on Jul 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To prevent ugly JavaScript errors in case somebody comes to your pop-up content via an SERP or something else goes wrong it may be worth checking that there is an opener and it hasn't been closed:

<body onload="if (window.opener && !window.opener.closed){window.opener.parent.location='thanks.html';}">
4:01 pm on Jul 8, 2002 (gmt 0)

10+ Year Member



I see what you mean, I hadn’t thought of that.

Is there or could there be a script that detected if a visitor is coming from a link other than the homepage and if they are redirected them to the home page?

Mak

4:19 pm on Jul 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As the thanks.html URL isn't specified anywhere other than in your scripting it's probably not that likely to get picked up by the SE spiders. Any SEOs seen them picking up scripted URLs before?

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.

9:39 pm on Jul 8, 2002 (gmt 0)

10+ Year Member



joshie76

thanks for the input, It's looks like a really cool script I'm going to try in out first chance I get.

I'll keep you posted

Thanks mak

 

Featured Threads

Hot Threads This Week

Hot Threads This Month