11
<!doctype html>
<html>
<head>
<title>page</title>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />

<meta name="apple-mobile-web-app-status-bar-style" content="black" />
</head>
<body>
<script>
function goToPage() {
    var pageUrl = 'http://www.google.com/';
    window.open(pageUrl);
}
</script>
<div id="installBtn" onclick="goToPage()">go to page</div>
</body>
</html>

The expected action is: when touch the div, a new window opens. This code works great in the iPhone's safari.

But when I tap "+" -> "Add to Home Screen", and press "go to page", no window is opened, and the page loads in the same screen.

How to force, by javascript, a new window to open in the standalone mode?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Eduardo Abreu
  • 245
  • 2
  • 3
  • 9

4 Answers4

1

The below question does mention a possible JavaScript solution out of the top voted answers, which constructs the anchor element and dispatches the 'click' event on it.

Question: Force link to open in mobile safari from a web app with javascript
Answer: https://stackoverflow.com/a/8833025/1441046

Alternatively if you can use an anchor element (I know you asked how to do it in JavaScript) you can do the following:

<a id="installBtn" href="http://www.google.com/" target="_blank">go to page</a>

Other related questions:

iPhone window.open(url, '_blank') does not open links in mobile Safari

Community
  • 1
  • 1
JonWarnerNet
  • 1,112
  • 9
  • 19
0

This works for me. Doesn't work when requesting it from html, only from JS.

window.open('[url]','_system');
Matt
  • 1,081
  • 15
  • 27
0

you can use childbrowser to open in the standalone mode

Or you can use this

window.location = url(your Url);
Tom
  • 4,257
  • 6
  • 33
  • 49
Musman
  • 31
  • 6
-10

There you go! (if you still need it)

<script>
    if(window.navigator.standalone === true) 
     document.write('Standalone');
    else
     document.write('Web browser');
</script>

R.

Remi Grumeau
  • 302
  • 2
  • 7
  • 1
    Welcome to stack overflow :-) Please look at [answer]. You should provide some information why your code solves the problem. Code-only answers aren't useful for the community. – JimHawkins Feb 09 '17 at 09:23
  • Well that's a 2012 message but fair enough! This code tests if the web engine is used in standalone mode or not. AFAIK only supported by iOS – Remi Grumeau Feb 09 '17 at 10:45