Hi,
How can I do this so that both happen at the same time?
Any help is greatly appreciated,
-Corbb
P.S. I’m rather new to JavaScript, so please provide as much code and documentation as possible. Thanks!
Hi,
How can I do this so that both happen at the same time?
Any help is greatly appreciated,
-Corbb
P.S. I’m rather new to JavaScript, so please provide as much code and documentation as possible. Thanks!
Quite simple; just call the closePopup() function on unload.
If you want the popup closed when clicking on a specific link, call closePopup() on the onClick event for the link instead.
(The call to closePopup() in openPopup() is just an extra thing, to avoid more than 1 popup window opened by this page)
<html>
<head>
<script language="JavaScript">
var w = null;
function openPopup()
{
closePopup();
w = window.open('', '', 'width=200,height=200');
w.document.write('Hello, I just popped up');
}
function closePopup()
{
if(w != null)
{
w.close();
}
}
</script>
</head>
<body onUnload="closePopup();">
<a href="javascript:void(0);" onclick="openPopup();">Open popup</a>
<br>
<a href="anotherpage.htm">A link to another page</a>
</body>
</html>
OK, read your question one more time and realized that you wanted to change the parent window’s location and then close the popup - from the popup window.
Here’s an updated openPopup() function and a new change() function (same html and closePopup() code as in the previous post)
function openPopup()
{
closePopup();
w = window.open('', '', 'width=200,height=200');
var s = 'Hello, I just popped up<br>';
s += '<a href="javascript:void(0);" onClick="window.opener.change();">';
s += 'Change parent and close me</a>'
w.document.write(s);
}
function change()
{
window.location.href = 'anotherpage.htm';
}
Hi,
Thanks for your help. However, I’m very confused.
I have a popup window that opens when somebody visits my website. There is a form in this winodw where somebody enters their email address. Then a “thank you” page comes up. In the “thank you” page, it says “If you have any questions, please don’t hesitate to contact us.” The contact us is linked to /contactus.htm. When somebody clicks on “contact us,” I want the popup to close and then the parent window to change to contactus.html. How can I do this?
You may have already answered this, but I’m confused.
Thanks,
Corbb
I want the popup to close and then the parent window to change to contactus.html. How can I do this?
In the popup, add this link:
<a href=“javascript:void(0);” onClick=“window.opener.location.href=‘contactus.html’;”>Contact us</a>
And, of course, if you don’t have the
<body onUnload=“closePopup();”>
in the main page, you must add
window.close; to the link in the popup:
<a href=“java script:void(0);” onClick=“window.opener.location.href=‘contactus.html’;window.close();”>Contact us</a>
jofa,
Thank you very much!
-Corbb
How about a twist on this:
I have a page with a link that loads another page. No problem, straight html. However the loaded page takes some time to load since it’s parsing some PHP. So I created a little javascript that opens a new popup window that says “your page is being loade, chill out” or something. I called this popup window “popup” from the javascript that opens it:
onClick="window.open(‘url’, ‘popup’, width, height)
Now what I want to do is close the popup window once the called page loads. So I thought that if I put into the called page:
<body onLoad="window.close(‘popup’)>
it would do the trick, but all it does is close itself! How can I tell it to close the popup window?