Javascript js打开弹出窗口并在另一个页面中访问其元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10468136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:27:11  来源:igfitidea点击:

js open popup window and acces its element in another page

javascriptjquerypopup

提问by Suneth Kalhara

I have a problem with js popup window.

我有 js 弹出窗口的问题。

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
  • 第一页 - 使用 html5 音乐播放器打开弹出窗口
  • 第二页 - 当用户点击主页上的按钮时需要暂停音乐

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

第二页我想在不重新加载弹出窗口的情况下访问 mypopup 窗口元素

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

我只需要如何访问打开的弹出元素而不使用 JS 或 JQuery 中断其源的方法

回答by mplungjan

Same origin (domain, port and protocol)?

同源(域、端口和协议)?

Plain JS:

普通JS:

from page1

从第 1 页

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

from page 2

从第 2 页

var popup = window.open('','mypopup');
// now popup is known again
popup.document.getElementById("player").someFunction();