简体   繁体   English

使用来自 iFrame 的链接打开新标签页 - 页面被阻止

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


I have a page with an iFrame. 我有一个带有 iFrame 的页面。 This iFrame has some ajax server communication via jQuery. 此 iFrame 通过 jQuery 进行一些 ajax 服务器通信。 In my iFrame I have several links which should be opened in a new tab or popup on click. 在我的 iFrame 中,我有几个链接应该在新选项卡或点击弹出窗口中打开。 This works perfectly fine for static links, where I have a fixed URL. 这对于我有固定 URL 的静态链接非常有效。 These links look like this one: 这些链接看起来像这样:
 <a href="https://www.google.com" target="_blank" rel="noopener noreferrer">Google Test</a>

As I mentioned, this link works perfectly fine. 正如我所提到的,这个链接工作得很好。 However, I have another link which gets assigned its URL based on the feedback from the server query. 但是,我有另一个链接,它根据服务器查询的反馈分配了 URL。 The link looks like this: 该链接如下所示:
 <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>

In my Javascript I am using this code to set the URL:在我的 Javascript 中,我使用这段代码来设置 URL:

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

When I am clicking on this link a new tab is opened but Chrome tells me "my_domain is blocked".当我单击此链接时,会打开一个新选项卡,但 Chrome 告诉我“my_domain 已被阻止”。 This page has been blocked by Chrome.此页面已被 Chrome 阻止。 ERR_BLOCKED_BY_CLIENT. ERR_BLOCKED_BY_CLIENT。 When I copy the URL from the tab and enter it in another private tab, the page opens just fine.当我从选项卡中复制 URL 并将其输入到另一个私人选项卡中时,该页面打开得很好。
I also tried to open the link in a popup.我还尝试在弹出窗口中打开链接。 The popup opens but the I am getting the same feedback that the page is blocked.弹出窗口打开,但我收到与页面被阻止相同的反馈。 The code looks like this:代码如下所示:

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

I am wondering why the link is working for the static link but not when I assign the URL via jQuery.我想知道为什么链接适用于静态链接,但当我通过 jQuery 分配 URL 时却不起作用。
BTW: my iFrame header looks like this:顺便说一句:我的 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>

After some additional research, I was able to fix my issue.经过一些额外的研究,我能够解决我的问题。 I had to add an additional allowance to the sandbox of the iFrame which was我不得不在 iFrame 的沙盒中添加额外的津贴

allow-popups-to-escape-sandbox

Interrestingly, this works for opening the link as a popup as well as in a new tab.有趣的是,这适用于将链接作为弹出窗口以及在新选项卡中打开。
BTW: it seems as if Firefox does not require this flag as it already worked in Firefox before.顺便说一句:似乎 Firefox 不需要这个标志,因为它之前已经在 Firefox 中工作过。

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

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