使用Javascript从父窗口访问子窗口元素
我需要从父窗口访问子窗口元素。我已经在下面编写了示例片段 父HTML:使用Javascript从父窗口访问子窗口元素,javascript,Javascript,我需要从父窗口访问子窗口元素。我已经在下面编写了示例片段 父HTML: 父母亲 div{ 浮动:左; 光标:指针; } var SubpopUpWin=“”; 函数Opennew(passedURL){ SubpopUpWin=window.open(“popups.html”,“u blank”,“toolbar=no,status=no,menubar=no,scrollbars=yes,resizeable=yes,copyhistory=yes”);SubpopUpWin.docume
父母亲
div{
浮动:左;
光标:指针;
}
var SubpopUpWin=“”;
函数Opennew(passedURL){
SubpopUpWin=window.open(“popups.html”,“u blank”,“toolbar=no,status=no,menubar=no,scrollbars=yes,resizeable=yes,copyhistory=yes”);SubpopUpWin.document.getElementById(“ifrm”).src=passedURL;
SubpopUpWin.document.getElementById(“ifrm_title”).innerHTML=passedURL;
}
谷歌
雅虎
宾
popups.html
小孩
div{
浮动:左;
}
在上面的代码中没有工作。甚至我也使用了下面的脚本
<script type="text/javascript">
var SubpopUpWin="";
function Opennew(passedURL){
SubpopUpWin = window.open("popups.html", '_blank','toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes');
SubpopUpWin.onload=function(){
SubpopUpWin.document.getElementById("ifrm").src=passedURL;
SubpopUpWin.document.getElementById("ifrm_title").innerHTML=passedURL;
}
}
</script>
var SubpopUpWin=“”;
函数Opennew(passedURL){
SubpopUpWin=window.open(“popups.html”、“_blank”、“toolbar=no、status=no、menubar=no、scrollbars=yes、resizeable=yes、copyhistory=yes”);
subpopuwin.onload=函数(){
SubpopUpWin.document.getElementById(“ifrm”).src=passedURL;
SubpopUpWin.document.getElementById(“ifrm_title”).innerHTML=passedURL;
}
}
上述代码也不起作用。
请分享您的建议/解决方案
谢谢我觉得这是出于安全考虑。您可以尝试以下方法:
<html>
<head>
<title>Parent</title>
<style>
div {
float: left;
cursor: pointer;
}
</style>
<script type="text/javascript">
var SubpopUpWin = "";
var testUrl = "";
function Opennew(passedURL){
testUrl = passedURL;
SubpopUpWin = window.open("popups.htm", '_blank', 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes');
}
</script>
</head>
<body>
<div onclick="Opennew('http://www.google.com')">
Google
</div>
<div onclick="Opennew('http://www.yahoo.com')">
Yahoo
</div>
<div onclick="Opennew('http://www.bing.com')">
Bing
</div>
</body>
父母亲
div{
浮动:左;
光标:指针;
}
var SubpopUpWin=“”;
var testUrl=“”;
函数Opennew(passedURL){
testUrl=passedURL;
SubpopUpWin=window.open(“popups.htm”、“_blank”、“toolbar=no、status=no、menubar=no、scrollbars=yes、resizeable=yes、copyhistory=yes”);
}
谷歌
雅虎
宾
小孩
div{
浮动:左;
}
document.getElementById(“ifrm”).src=window.opener.testUrl;
将
passedURL
作为查询字符串传递到popups.html
怎么样?我没有检查这个。。。但是我们可以使用window.opener轻松地从子窗口访问父窗口元素;尝试使用setTimeoutYes,我知道这一点。但是setTimeout也不起作用…通过使用查询字符串,它起作用。。。
<script type="text/javascript">
var SubpopUpWin="";
function Opennew(passedURL){
SubpopUpWin = window.open("popups.html", '_blank','toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes');
SubpopUpWin.onload=function(){
SubpopUpWin.document.getElementById("ifrm").src=passedURL;
SubpopUpWin.document.getElementById("ifrm_title").innerHTML=passedURL;
}
}
</script>
<html>
<head>
<title>Parent</title>
<style>
div {
float: left;
cursor: pointer;
}
</style>
<script type="text/javascript">
var SubpopUpWin = "";
var testUrl = "";
function Opennew(passedURL){
testUrl = passedURL;
SubpopUpWin = window.open("popups.htm", '_blank', 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes');
}
</script>
</head>
<body>
<div onclick="Opennew('http://www.google.com')">
Google
</div>
<div onclick="Opennew('http://www.yahoo.com')">
Yahoo
</div>
<div onclick="Opennew('http://www.bing.com')">
Bing
</div>
</body>
<html>
<head>
<title>Child</title>
<style>
div {
float: left;
}
</style>
</head>
<body>
<div>
<div id="ifrm_title">
</div>
<div style="margin-top:20px">
<iframe id="ifrm" src="" width="470" height="270" frameborder="0" style="margin-top: 34px" scrolling="no">
</iframe>
<script type="text/javascript">
document.getElementById("ifrm").src = window.opener.testUrl;
</script>
</div>
</div>
</body>