【发布时间】:2017-02-28 06:14:14
【问题描述】:
我使用以下内容打开包含一些页面内容的新选项卡(在新进程中),
var p = document.getElementById("myElement");
var a = document.createElement('a');
a.setAttribute('href',".../mypage.html");
a.setAttribute('rel',"noreferrer");
a.setAttribute('target',"_blank");
p.appendChild(a);
a.click();
http://news.softpedia.com/news/Force-Google-Chrome-to-Open-Links-in-New-Processes-128962.shtml
这正在工作,新标签页已打开,其中包含 myPage.html 内容。
假设这是 myPage(仅用于示例...)我应该如何访问它?
<!DOCTYPE html>
<html>
<body>
<h1> Heading</h1>
<p> paragraph.</p>
<button type="button">Click Me!</button>
</body>
</html>
现在让我们进入棘手/高级:)部分...
当你使用window.open(我不能使用)这很简单,因为你可以使用各种技术。
1. using window object
2. post message
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
3. cookies
4. localStorage
但在这里我打开这个新页面时没有使用 window.open 获得的参考
我的问题是:
如果我想更改某些内容,如何访问这个新的标签 dom
【问题讨论】:
-
嗨,我在发帖前给你 +1 搜索
-
@MarnyA.López - 谢谢 :)
-
我希望您对同源策略没有任何问题。 1)任何页面都可以是“父”吗? 2)您需要双向发送消息吗? (父母 -> 孩子或孩子 -> 父母)
-
@fremail - 目前我没有域问题...我需要从“子选项卡”向“父选项卡”发送消息,如果您有想法请提供一些示例,谢谢!
-
你说你不能使用window.open API然后说你根本不能使用window?怎么会?要求避免 XY...
标签: javascript html google-chrome service-worker