1

There is a page containing an iframe that loads a page from the same domain. The page is not executing when navigating using and anchor tag that has target set to "_blank".

Getting the following error

Uncaught DOMException: Blocked a frame with origin "https://some.url.com" from accessing a cross-origin frame. at https://some.url.com/test/:342:23

When target blank is removed the link works fine.

How this issue can be fixed ?

Edit:

It is an MVC application that has two views. The first one Holds the Anchor tag like below

<a class="wsite-button wsite-button-small wsite-button-highlight" href="https://stackoverflow.com/questions/49252609/iframe-execution-blocked-when-navigated-using-anchor-tag-having-target-blank" target="_blank">
    <span class="wsite-button-inner">Click here to access</span>
</a>

The above link redirects to another page that contains an iframe that is loading some html page.

The issue only occurs when target="_blank" is set.

JO3-W3B-D3V
  • 2,124
  • 11
  • 30
Mayank
  • 1,351
  • 5
  • 23
  • 42
  • Could you provide some source code please? – JO3-W3B-D3V Mar 13 '18 at 09:50
  • @JO3-W3B-D3V I have updated the question. Please check is this helpful. – Mayank Mar 13 '18 at 09:59
  • I've just had a quick read up, apparently it's a bit of a grey area, as for the exact reason why it's returning that error I'm not sure. An alternative could be implementing it with JS? - Sometimes a browser will flat out block the use of `target="_blank"` due to the simple fact that it could be an ad... This is what I've read up about the issue, it's interseting as I've never had such a problem, personally speaking. [Link to similar issue](https://stackoverflow.com/questions/29444051/link-with-target-blank-does-not-open-in-new-tab-in-chrome) – JO3-W3B-D3V Mar 13 '18 at 10:06
  • One possible solution could be something like adding this on the a tag....? `onclick="window.open(this.href, '');` – JO3-W3B-D3V Mar 13 '18 at 10:11
  • 1
    I am getting the same error using the above JavaScript as well. – Mayank Mar 13 '18 at 10:16
  • There is no iframe on the first page that redirects. Iframe is only on the redirected page. I think browser is treating this newly created tab (using _blank) with some restrictions. When I manually enter the same address on a new window of the browser the page works fine. – Mayank Mar 13 '18 at 10:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/166748/discussion-between-jo3-w3b-d3v-and-mayank). – JO3-W3B-D3V Mar 13 '18 at 10:57

0 Answers0