简体   繁体   English

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

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

I have a page hosted on https with iframe content that has http links within it. 我有一个托管在https上的页面,其中包含iframe内容,其中包含http链接。 The framed content is on another domain but is https but I want to be able to make the http links open into a new tab. 框架内容位于另一个域,但为https,但我希望能够将http链接打开到新选项卡中。 So far I have not been able to acheive this through jquery. 到目前为止,我还无法通过jquery实现这一点。

Example. 例。

 <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> 

You can try this with various mixed content pages. 您可以尝试使用各种混合内容页面。 You will notice the placeholder link "WE ARE STILL HERE" opens perfectly to a new window while anything in the iframe will not load without choosing to allow insecure content. 您会注意到,占位符链接“我们仍然在这里”完美地打开了一个新窗口,而如果没有选择允许不安全的内容,则不会加载iframe中的任何内容。

Any help will be greatly appreciated. 任何帮助将不胜感激。

If iframe url and main page url are on the same domain, well it could be done by this code to access elements which are placed inside iframe 如果iframe网址和主页网址位于同一个域中,那么可以通过此代码来访问放置在iframe中的元素

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

But if not actually there is not way 但是如果没有,那实际上是没有办法的

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

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