Recently I had a requirement, in my web page which contain four links, each link open a popup window. I am using a common JavaScript function to open popup window as given below,
Now when click on a link, it opens a popup window, which contain a data entry form, I entered some information into that form. Then I need to review other information, from other popup window, so I go back to the main window, click on another link, a new popup window get open which contain the information I need to review. I get the information and close this popup window, so now I am on the main window, then again I click on the link for that data entry form, so the popup window comes up but I lost the information that I have entered, that's because I am relodiing the popup window once again. So here the question arise,
Let us see how it works,
Now when click on a link, it opens a popup window, which contain a data entry form, I entered some information into that form. Then I need to review other information, from other popup window, so I go back to the main window, click on another link, a new popup window get open which contain the information I need to review. I get the information and close this popup window, so now I am on the main window, then again I click on the link for that data entry form, so the popup window comes up but I lost the information that I have entered, that's because I am relodiing the popup window once again. So here the question arise,
- Is their any way, I can check out the if popup window is already open from parent window, without having the object of popup window just by the name?
- If the popup window is already open how can I just set the focus to it, rather then reloading it?
- Can I refer a popup window from a parent window, even after refreshing the parent window?
Let us see how it works,
- When attempt to open the window again with the same name in the second parameter of the windows open method, you will to get the windows handle. If the window is already open, it will return the handle of the opened window or it will open a new window and return it's handle
- The first parameter (the url) is passed as an empty string, so the page will not get redirected which will result in the contents of the window remaining unchanged.
Note : You cannot get the handle if the page is not on the same host as its opener
This was helpful...thank you.
ReplyDeleteNice trick.. very helpful... Thanks...
ReplyDeleteThank you for this. I have spent ages trying to find a solution including using cookies to store the window object (JSON format), glad I found your blog. Such a simple solution
ReplyDeleteThis solution is great! Thanks!
ReplyDeletePlease add a hyperlink code also.
ReplyDeleteHi. It is a nice solution..Thanks
ReplyDeletelet me try this...
ReplyDeleteThank you so much. This is exactly what I needed! Very elegant.
ReplyDeleteexcellent! Thank you - you can simplify the check a little to be:
ReplyDeleteif (targetWin.location != pageURL) targetWin.location = pageURL;
targetWin.focus();
doesnt work in new chrome
ReplyDeleteNice solution, but how it works with cross domain content in child window ? doesn't it throw "Permission denied" Error ?
ReplyDeleteTanks!!! Saved my day!!!
ReplyDeleteThank you so much for this valuable information! You saved my day! Thanks to your tip I was able to get a block diagram with hot-arrows to navigate between pages working just in time for a demo for the "big boss". You went the extra mile!
ReplyDelete