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