繁体   English   中英

强制在iframe中打开“ http”链接以在新标签页中打开

[英]Forcing “http” links in an Iframe to open in new tab

我有一个托管在https上的页面,其中包含iframe内容,其中包含http链接。 框架内容位于另一个域,但为https,但我希望能够将http链接打开到新选项卡中。 到目前为止,我还无法通过jquery实现这一点。

例。

 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(function() { $("a[href^='http://']:not([href*='https://'])").each(function() { $(this).click(function(event) { event.preventDefault(); event.stopPropagation(); window.open(this.href, '_blank'); }).addClass('externalLink'); }); }); </script> </head> <body> <div class="banner"> <a href="http://example.com">WE ARE STILL HERE</a> <iframe name="home" scrolling="auto" height="100%" width="100%" noresize="true" src="https://www.example.com"> </iframe> </div> </body> </html> 

您可以尝试使用各种混合内容页面。 您会注意到,占位符链接“我们仍然在这里”完美地打开了一个新窗口,而如果没有选择允许不安全的内容,则不会加载iframe中的任何内容。

任何帮助将不胜感激。

如果iframe网址和主页网址位于同一个域中,那么可以通过此代码来访问放置在iframe中的元素

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

但是如果没有,那实际上是没有办法的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM