homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript help
Changing the original window from a pop-up
flashmastermak




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

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.

 

tedster




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

Welcome to the forum, flashmastermak. Try this:

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

flashmastermak




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

thanks tedster

It works perfectly

Mak

joshie76




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

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';}">

flashmastermak




msg:1487409
 4:01 pm on Jul 8, 2002 (gmt 0)

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

joshie76




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

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.

flashmastermak




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved