簡體   English   中英

使用來自 iFrame 的鏈接打開新標簽頁 - 頁面被阻止

[英]Opening a new tab with link from iFrame - Page is blocked


我有一個帶有 iFrame 的頁面。 此 iFrame 通過 jQuery 進行一些 ajax 服務器通信。 在我的 iFrame 中,我有幾個鏈接應該在新選項卡或點擊彈出窗口中打開。 這對於我有固定 URL 的靜態鏈接非常有效。 這些鏈接看起來像這樣:
 <a href="https://www.google.com" target="_blank" rel="noopener noreferrer">Google Test</a>

正如我所提到的,這個鏈接工作得很好。 但是,我有另一個鏈接,它根據服務器查詢的反饋分配了 URL。 該鏈接如下所示:
 <a href="#" id="documentLink" rel="noopener noreferrer" target="_blank"> <img alt="PDF" src="../images/icons/icon_pdf.svg" style="width:30px;height:30px;margin-right:15px;"> <span>View Report</span> </a>

在我的 Javascript 中,我使用這段代碼來設置 URL:

 $( '#documentLink' ).attr('href',data.documentLinkClickable);

當我單擊此鏈接時,會打開一個新選項卡,但 Chrome 告訴我“my_domain 已被阻止”。 此頁面已被 Chrome 阻止。 ERR_BLOCKED_BY_CLIENT。 當我從選項卡中復制 URL 並將其輸入到另一個私人選項卡中時,該頁面打開得很好。
我還嘗試在彈出窗口中打開鏈接。 彈出窗口打開,但我收到與頁面被阻止相同的反饋。 代碼如下所示:

 $( '#documentLink' ).attr('onclick','javascript:window.open("'+data.documentLinkClickable+'","_blank","toolbar=0, location=0, menubar=0, height=800, width=1200"); return false;');

我想知道為什么鏈接適用於靜態鏈接,但當我通過 jQuery 分配 URL 時卻不起作用。
順便說一句:我的 iFrame 標頭如下所示:

 <iframe id="25_IFrame2" class="iframe" sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads" src="https://my_domain/my_page?my_parameter" scrolling="yes" style="width: 1903px; height: 489px;"></iframe>

經過一些額外的研究,我能夠解決我的問題。 我不得不在 iFrame 的沙盒中添加額外的津貼

allow-popups-to-escape-sandbox

有趣的是,這適用於將鏈接作為彈出窗口以及在新選項卡中打開。
順便說一句:似乎 Firefox 不需要這個標志,因為它之前已經在 Firefox 中工作過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM