This has me really stymied - I am writing some HTML to a page using jQuery. Within that HTML is a basic link:
<a href="" 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?
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." 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?
Share Improve this question edited Sep 25, 2018 at 20:29 Randall Jamison asked Sep 25, 2018 at 19:00 Randall JamisonRandall Jamison 3391 gold badge3 silver badges15 bronze badges 3- Are you sure that these devices haven't disabled popup windows? – Simon Jensen Commented Sep 25, 2018 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 Commented Sep 25, 2018 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 Commented Sep 26, 2018 at 6:05
2 Answers
Reset to default 1In 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 patibility table link are wele.
Edit 01 Feb. 2021: Major browsers and weird edge cases. window.open
fully hangs Firefox on some devices.
// mon 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./a/46958731/6357894
window.open(query, 'about:blank', 'noopener');
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