Html 在新窗口中打开 iframe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19759880/
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
Open iframe in a new window
提问by Alex Chen
How do I open an iframe in a new window? I tried with "scrolling='auto'". It did not work.
如何在新窗口中打开 iframe?我试过“滚动=“自动”。这没用。
I put my code here:
我把我的代码放在这里:
<iframe width="572px" scrolling="auto" height="335px"
frameborder="1" src="http://XXXX.com/iframe-page"
style="border: 0px none #ffffff;" name="national-campaign"
marginheight="0px" marginwidth="0px">
</iframe>
Any ideas? Cheers.
有任何想法吗?干杯。
回答by Kamuran S?necek
You can do it with jquery and window.open method.
您可以使用 jquery 和 window.open 方法来完成。
HTML:
HTML:
<iframe id="iframe" width="572px" scrolling="auto" height="335px"
frameborder="1" src="http://XXXX.com/iframe-page"
style="border: 0px none #ffffff;" name="national-campaign"
marginheight="0px" marginwidth="0px">
</iframe>
JS :
JS:
var iframe = $("#iframe");
var newWindow = window.open(iframe.attr(src), 'Dynamic Popup', 'height=' + iframe.height() + ', width=' + iframe.width() + 'scrollbars=auto, resizable=no, location=no, status=no');
newWindow.document.write(iframe[0].outerHTML);
newWindow.document.close();
iframe[0].outerHTML = ''; // to remove iframe in page.
回答by Alessandro Incarnati
Try to add target="_top"
inside that link.
尝试target="_top"
在该链接内添加。
or alternatively if you need to open a new page from a link inside an iframe if i understood correctly you can:
或者,如果您需要从 iframe 内的链接打开一个新页面,如果我理解正确的话,您可以:
Using jQuery:
使用jQuery:
$('iframe a').attr('target', '_blank');
回答by kosherjellyfish
I would recommend that you just use a hyperlink to another page rather than an iframe. Or a screenshot image that is actually a link.
我建议您只使用指向另一个页面的超链接而不是 iframe。或者实际上是链接的屏幕截图图像。
Some users may be 'smart' enough to right-click within the iframe (in internet explorer) and select a 'open in new window' option, but others wouldn't do that.
一些用户可能足够“聪明”,可以在 iframe 内(在 Internet Explorer 中)右键单击并选择“在新窗口中打开”选项,但其他人不会这样做。
回答by Christophe
The easy way is to use a hyperlink with an attribute target="_blank".
简单的方法是使用带有属性 target="_blank" 的超链接。
If the height and width are important to you (cf. your example), then you can use the JavaScript method window.open.
如果高度和宽度对您很重要(参见您的示例),那么您可以使用 JavaScript 方法window.open。