According to my research:
You will not have something reliable to 100%.
Simply attempting to open a new window with JS triggers popup blockers; making it an unreliable way to test if a new window can be opened.
You are right it is absolutely not reliable ... window.open()
is blocked (even with a trick like window.open(url, '_blank');window.focus();
), click()
is also blocked (on a link containing target="_blank"), just as evt = document.createEvent("MouseEvents");evt.initEvent("click", true, true);
...
But anyway : if the WebView does not allow opening a link in a new tab, then it will work ok. But as you are implying a Webview may authorize it. In this case you will not know if you are in a webview or not. It is easy to detect whether an open link in new tab finally opened in the same or not (can be tested in javascript in a non-displayed iframe), but if the link is opened in a browser, you have no way of knowing (and imagine the user experience with a javascript code that opens a new tab in the browser from an application...). As Dave Alperovich said, you can not know in advance what will be blocked or not, without having tried. So you should not look on that side.
There are no reliable features or behavior that differentiates a Webview from a web browser. In a webview you have all what you get in a browser (cookies, WebStorage ...). User agent has its imperfections but it will works in many cases. There are explanations here or here to build it.