简体   繁体   中英

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


I have a page with an iFrame. This iFrame has some ajax server communication via jQuery. In my iFrame I have several links which should be opened in a new tab or popup on click. This works perfectly fine for static links, where I have a fixed 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. 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:

 $( '#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". This page has been blocked by Chrome. ERR_BLOCKED_BY_CLIENT. When I copy the URL from the tab and enter it in another private tab, the page opens just fine.
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.
BTW: my iFrame header looks like this:

 <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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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