8

I have a problem with js popup window.

I open a popup and try to access its elements in another page page, no success, and I don't want to reload the popup source, I simply want access a element of the opened popup

Ex -

  • 1st page - opened popup with html5 music player
  • 2nd page - need to pause the music when user click on button on main page

1st page

var popup = window.open("test.html","mypopup","width=500,height=300");

2nd page I want to access mypopup windows elements without reloading the popup

I only need the way how to access opened popup elements without interrupting its sources using JS or JQuery

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Suneth Kalhara
  • 1,116
  • 4
  • 16
  • 40
  • 1
    Same origin (domain, port and protocol)? Plain JS: `popup.document.getElementById("player").someFunction()` – mplungjan May 06 '12 at 04:54

1 Answers1

11

Same origin (domain, port and protocol)?

Plain JS:

from page1

var popup = window.open("test.html","mypopup","width=500,height=300");
popup.document.getElementById("player").someFunction();

from page 2

var popup = window.open('','mypopup');
// now popup is known again
popup.document.getElementById("player").someFunction();
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • What happend if i dont have access to the code that invokes `popup`? but still want to access the DOM from another page? – Ethaan May 04 '17 at 05:26
  • Please ask your own question... If the code that invokes it gave the popup a name or used a handle you can use it like I show in page 2- if it just does a `window.open("url.html")` then not. If you have scripting access to the page, you can rewrite the function that pops the page. `function popup() { /* myVersion of this */}` will overwrite `function popup() { /* their version */}` if you load yours after theirs and keep the name – mplungjan May 04 '17 at 06:51