javascript 使用 jQuery 在新窗口中打开 iframe?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12620461/
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-10-26 16:41:47  来源:igfitidea点击:

Open an iframe in a new window with jQuery?

javascriptjquery

提问by Jeff Erickson

I have a page embedded with an iframe in a Wordpress post, and I want to add a link in the iframe that, when clicked, will open that iframe's html page in a new window. I want to be able to do this without knowing the URL of that iframe. Is this possible? Thank you!

我在 Wordpress 帖子中有一个嵌入了 iframe 的页面,我想在 iframe 中添加一个链接,单击该链接后,将在新窗口中打开该 iframe 的 html 页面。我希望能够在不知道该 iframe 的 URL 的情况下执行此操作。这可能吗?谢谢!

回答by Anoop

Open window using window.open. you can set height, width and other properties of child window. jsfiddle.

使用 window.open 打开窗口。可以设置子窗口的高度、宽度等属性。jsfiddle

   <a href='javascript:void(0)'  onClick="window.open(location,'_blank','width=800, height=900'); return false;" >Html name </a>

jQuery:

jQuery:

$('a').click(function(){
       window.open(location,'_blank','width=800, height=900'); 
  return false; 

});

回答by chris.ribal

In jquery you just could pass the iframe's src value in an javascript window.open():

在 jquery 中,您只需在 javascript window.open() 中传递 iframe 的 src 值:

window.open($("iframe.test").attr("src"), "Window Title", "width=300,height=400,left=100,top=200");

回答by Marc Barbeau

No need for jQuery. You can use JavaScript to get the src of the iFrame using the ID.

不需要 jQuery。您可以使用 JavaScript 通过 ID 获取 iFrame 的 src。

 function popOut() {
        var src = document.getElementById('popOutiFrame').src;
        window.open(src);
    }

Next, call the Script with a button

接下来,使用按钮调用脚本

<button type="button" class="close" data-dismiss="modal"    onclick="popOut()">
    <!--Optional: Font Awesome expand icon-->
    <i class="fa fa-expand" aria-hidden="true"></i>
</button>

<iframe id='popOutiFrame' src='http://example.com'></iframe>

Demo

演示

回答by Man Programmer

Try this

试试这个

<a href='pathofhtml' target=_blank >Html name </a>