6

This has me really stymied - I am writing some HTML to a page using jQuery. Within that HTML is a basic link:

<a href="http://someurl.com" target="_blank" class="external-link">Link Text</a>

The issue is that for some reason, on certain mobile devices (Google Pixel and some iPhones), the link will NOT open in a new tab (either Chrome or Safari). So I tried doing it with JavaScript, using a click event on .external-link - same issue. It just opens in the same browser window on these problematic devices (works fine on mine).

I have confirmed that either way (target="_blank" or JS) does work on other multiple devices, including my Android phone. There are no settings that I can see in Chrome/Safari on these devices where it is not working that would be causing this behavior.

Any guesses as to the issue?

Randall Jamison
  • 299
  • 3
  • 13
  • Are you sure that these devices haven't disabled popup windows? – Simon Jensen Sep 25 '18 at 20:30
  • Popups are disabled - my understanding is that the setting only applies to popup *ads* not to a link opening a new tab. I have popups disabled on my phone as well, and the link is working as expected. – Randall Jamison Sep 25 '18 at 21:37
  • Try and enable the popups and then test again. I once had the same problem and it was that popups was disabled. That setting work different from browser to browser. – Simon Jensen Sep 26 '18 at 06:05

2 Answers2

1

In modern browsers about:blank as target should do the trick.
Used it as target for window.open in 2018 or in the end of 2017 for Desktop/Mobile/WebView app (probably _blank didn't work as expected across browsers back then).
Clarifications about spec or browser source code according to which it works and compatibility table link are welcome.

Edit 01 Feb. 2021: Major browsers and weird edge cases. window.open fully hangs Firefox on some devices.

// common mobile browsers
var link    =   document.createElement('a');
link.setAttribute('rel', 'noopener noreferrer');
link.setAttribute('target', 'about:blank');
link.setAttribute('href', query);
link.click();
// other custom browsers
// noopener,noreferrer - https://stackoverflow.com/a/46958731/6357894
window.open(query, 'about:blank', 'noopener');
lostero
  • 36
  • 6
0

A couple things you can try:

In case it's not just a typo in the post, make sure you're using target="_blank" instead of target="blank". The underscore is required for the keyword.

If you're linking to a website that you don't own, you should also include rel="noopener". That may not solve this problem on its own, but it's good practice

Hofma Dresu
  • 432
  • 3
  • 13