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