Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何创建指向iframe';现在在哪里?_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 如何创建指向iframe';现在在哪里?

Javascript 如何创建指向iframe';现在在哪里?,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,例如,如果我有一个设置为google.com的iframe,那么有人会在iframe中搜索,然后加载到iframe中。我想在iframe下面有一个链接,上面写着“转到页面”。当他们点击它时,它不一定会把他们带到google.com,而是带到他们当前在iframe中的任何页面。我尝试使用以下代码,但无效: <iframe id=frame src="http://www.google.com" scrolling=yes></iframe> <a id=moveOn

例如,如果我有一个设置为google.com的iframe,那么有人会在iframe中搜索,然后加载到iframe中。我想在iframe下面有一个链接,上面写着“转到页面”。当他们点击它时,它不一定会把他们带到google.com,而是带到他们当前在iframe中的任何页面。我尝试使用以下代码,但无效:

<iframe id=frame src="http://www.google.com" scrolling=yes></iframe>
<a id=moveOn href=# onclick='return false'>Click to go to page</a>
<script>
$('#moveOn').click(function(){
var src = document.getElementById('frame').contentDocument.location;
window.open(src);
});
</script>

$('#moveOn')。单击(函数(){
var src=document.getElementById('frame').contentDocument.location;
窗口打开(src);
});

有什么建议吗?谢谢:)

某些IE浏览器上不存在属性contentDocument。下面的代码应该更好,但是我没有在任何地方测试它

var src; if(document.getElementById('frame').contentDocument)src = document.getElementById('frame').contentDocument.location; else src = document.getElementById('frame').contentWindow.document.location var-src; if(document.getElementById('frame').contentDocument)src=document.getElementById('frame').contentDocument.location;
else src=document.getElementById('frame').contentWindow.document.location某些IE浏览器上不存在contentDocument属性。下面的代码应该更好,但是我没有在任何地方测试它

var src; if(document.getElementById('frame').contentDocument)src = document.getElementById('frame').contentDocument.location; else src = document.getElementById('frame').contentWindow.document.location var-src; if(document.getElementById('frame').contentDocument)src=document.getElementById('frame').contentDocument.location; else src=document.getElementById('frame').contentWindow.document.location