Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reference a popup window from two different pages?

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

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 in page-2.htm generates an error "playerWin is not defined". That is understandable because no variable named playerWin has been defined on page-2.htm.

My question is: Am I able to reference the popup window from page-2.htm?

like image 685
jessegavin Avatar asked Jan 22 '09 22:01

jessegavin


People also ask

How do I add a page to pop up?

Insert a button into the Orders List page grid. Show the Add page in a popup, close popup on clicking 'Save', and then refresh the List page. There is an added button to the List page that displays the Add page in a popup.

How do I get a pop up URL?

Open UiExplorer, and get the selector of that popup. Use an On Element Appear activity, put in the selector of that popup. in the On element Appear activity, place a Get Attribute activity, “url” to get the url of the popup.

How do I open multiple popup windows in asp net?

You can have multiple popups by changing the popup window name (pass the ID string as a second parameter, and make the ID the popup name, for example). They'll stay open, but they will not all stay on top of the main page.

How do I show a popup window in HTML?

You can simply use <iframe> to display the another page content in the modal content.


2 Answers

I just did a quick test even after you leave the opener page, the popup still have 'opener' object and you can access it. So either poll the opener and reset the reference, or add a timer after you leave the page to wait and then relink.

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>
like image 124
Glennular Avatar answered Nov 15 '22 06:11

Glennular


The answer is no. Most browsers will completely isolate the window and document from one navigation to the next. There is no where you could place the reference to the popup which will survive when you navigate to page2.

like image 20
AnthonyWJones Avatar answered Nov 15 '22 06:11

AnthonyWJones