在父窗口中更改url后,如何在父窗口中运行子窗口java脚本函数?
我想在父窗口上执行子窗口的java脚本函数,即使在更改父窗口中的URL之后也是如此。 我试过如下:在父窗口中更改url后,如何在父窗口中运行子窗口java脚本函数?,java,php,javascript,Java,Php,Javascript,我想在父窗口上执行子窗口的java脚本函数,即使在更改父窗口中的URL之后也是如此。 我试过如下: **Parent.html:** <html> <head> <title>Parent window document</title> </head> <body> <script type="text/Javascript"> function openChildWindow(
**Parent.html:**
<html>
<head>
<title>Parent window document</title>
</head>
<body>
<script type="text/Javascript">
function openChildWindow()
{
var s_url = "child.html";
var s_name = "ChildWindowDocument";
var s_specs = "resizable=yes,scrollbars=yes,toolbar=0,status=0";
var childWnd = window.open(s_url, s_name, s_specs);
var div = childWnd.document.getElementById("child_wnd_doc_div_id");
div.innerHTML = "Hello from parent wnd dddsfds";
}
</script>
<input type="button" value="Open child window document" name="sss" onclick="openChildWindow()" />
<div>Click me: nothing will happen.</div>
<div id="aaa" class="yourclass">
<p>This is a paragraph with a <span>span</span> where the paragraph's container has the class. Click the span or the paragraph and see what happens.</p>
This sentence is directly in the div with the class rather than in child element.
</div>
<div>Nothing for this div.</div>
<a>dsfsd</a>
</body>
</html>
**child.html:**
<html>
<head>
<title>Parent window document</title>
<script>
opener.document.body.onclick = function(e) {
var sender = (e && e.target) || (window.parent.event && window.parent.event.srcElement);
document.getElementById("id").value=sender.tagName;
}
</script>
</head>
<body>
<div id="child_wnd_doc_div_id">child window</div>
ID: <input type="text" id="id"/><br/>
Name: <input type="text" id="id"/><br/>
Xpath: <input type="text" id="id"/><br/>
CSS: <input type="text" id="id"/><br/>
</body>
</html>
**Parent.html:**
父窗口文档
函数openChildWindow()
{
var s_url=“child.html”;
var s_name=“ChildWindowDocument”;
var s_specs=“可调整大小=是,滚动条=是,工具栏=0,状态=0”;
var childWnd=window.open(s_url、s_名称、s_规范);
var div=childWnd.document.getElementById(“child_wnd_doc_div_id”);
div.innerHTML=“来自父wnd dddsfds的Hello”;
}
点击我:什么都不会发生。
这是一个具有跨距的段落,其中段落的容器具有类。单击跨度或段落,查看发生了什么
这个句子直接与类一起出现在div中,而不是在child元素中。
这个部门什么都没有。
dsfsd
**child.html:**
父窗口文档
opener.document.body.onclick=函数(e){
var sender=(e&&e.target)| |(window.parent.event&&window.parent.event.src元素);
document.getElementById(“id”).value=sender.tagName;
}
子窗口
ID:
名称:
Xpath:
CSS:
显然,我的想法是:在更改父窗口中的url后,我希望执行子窗口函数。我看到的唯一方法是:
观察开启器的卸载事件。当它触发时,尝试(在短时间超时后)重新分配onclick函数(以及onunload函数)
当然,只有当两个文档都放在同一个域下时,这才起作用