How can I link to a popup from two different pages?

I need to allow the user to click the link in "page-1.htm" and open a popup. Then, when the user views "page-2.htm" in the main browser window, I need to be able to link to the popup.

JavaScript in "page-1.htm"

var playerWin = window.open("player.htm", "playerWin", "width=300,height=130"); playerWin.play("song.mp3"); // play() is a function in player.htm 

JavaScript in "page-2.htm"

 playerWin.play("tune.mp3"); 

This code on page 2.htm generates a "playerWin not defined" error. This is understandable because no variable named playerWin is defined on page 2.htm.

My question is: can I link to a popup from page-2.htm?

+4
source share
5 answers

I just did a quick test even after you left the open page, the popup still has an β€œopening” object, and you can access it. Therefore, either try the opener, or reset the link, or add a timer after you leave the page to wait and then reconnect.

1.htm

 <script> var w = window.open("p.htm", "playerWin", "width=300,height=130"); </script> <a href="2.htm">2</a> 

p.htm

 <a href="javascript:opener.w=this;">re-link</a> 

2.htm

 <script> var w; </script> <a href="javascript:alert(w);">check</a> 
+5
source

The answer is no. Most browsers completely isolate the window and the document from one navigation to the next. There is no place where you could place a link to a pop-up window that will remain when you go to page2.

+2
source

You need to put page-1.htm in the iframe (which occupies the full browser window) ... then start and communicate with the popup through the parent window of page-1.

t. (sorry for the pseudo-code)

 user clicks on link in page-1 page-1 asks it parent window to open a popup popup opens user navigates away (in the iframe) user clicks a link in page-2 page-2 asks it parent window to close it popup 

As long as everything is in the same domain and the movement remains within the iframe, this should work

+1
source

I have not seen this before ... I'm going to suggest that you do this because you have and you do not have the opportunity to organize your pages in different ways.

Since you are using ASP.NET, just set the page value for the session. Then ask your player page to start an AJAX timer to check the session variable, and then take the appropriate action, since there is a handle in the popup window.

0
source

The accepted answer did not work for me in Firefox 12.0. I am currently working on a project in which the application must have constant knowledge of which pop-ups are open / closed when navigating from page to page or updating the current page. I use JavaScript cookies to store client information every time a popup opens or closes. Not perfect, but it's a good option if you don't need something that is 100% more reliable. It seems to me that an attempt to maintain JavaScript variables when reloading a page will always be much less reliable, and an attempt to store pop-up information on the server does not make sense, so what else remains besides cookies?

0
source

All Articles