Javascript pop-up windows and parent page refreshing
September 20, 2008
Filed under
Development, JavaScript
This subject is quite interesting and i was searching for examples for long. Then I managed to do something, true that only by combining many examples i’ve found.
Let’s see the code then I’ll try to explain everything.
function popUp(URL) {
window.open(URL, 'WindowName', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=400');
}
window.onload = popUp("http://example.com");
The above function will pop-up window which will contain the page you put as value in the popUp function. I’ve put http://example.com, you put whatever you like, but preferably from your own domain if you want to have access to the pop-up’s DOM. You can play with the toolbar,scrollbars,location variables till hurts, basically they define how the popped up window will look and act. I wrote the above script so to pop the window up when the page loads (window.onload) , if you don’t like that and the fact that this even is blocked by most pop-up blockers, you can put a HTML button or link somewhere in the page, like this:
Pop Up the window
As I said before, there’s a slight issue with the stuff if you use the window.onload, specifically that your pop-up much likely will be blocked by pop-up blockers. You don’t want that, and even if it succeeds to pop-up, it’s annoying for the visitor, so just don’t do it, please.
OK, now let’s see the the parent window refreshing. Prent window is the page which pop-up up the small window. The pop-up window is the child. Usually, we use the parent refresh if we want to transfer a variable from the pop-up to the parent. The script which has to be placed in the child, popped up window is the following script:
function Parent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow){
window.opener.progressWindow.close()
}
window.close();
}
and the button or link which closes and refreshes the parent window is
Click here to close this window and refresh the parent
A working example is situated here. It’s a loop so if your pop-up blocker doesn’t block the first pop-up, most likely you’ll get annoyed in no time.
And I think that was all. You can also transfer variables from one window to other, but that’s for another day… so, the show is over… there’s nothing to see here, pass over please.
Possible related posts (automatic):
Related posts brought to you by Yet Another Related Posts Plugin.



















Comments
Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
If you want to use your OpenID, fill out the field labeled "Website" with the OpenID URL. The other fields may remain empty.