简体   繁体   中英

window.open() does not work on iOS app using phone gap

I am writing an ios app using Phonegap, all i need in my app is that when the phonegap call the index.html the html page will redirect the user to my web site the thing is that the html does not redirect the app to my site, i do not care if the phone gap open the safari i just need it to redirect it to my site my code is:

<html>
<head>
<script type="text/javascript">
    function loadlink()
    {
        window.open("www.cnn.com");
    }
</script>
</head>
<body onload="loadlink()">        
</body>
</html>

Make your function look like this:

function loadlink() {
  window.location.href = "www.cnn.com";
}

Or even better

function loadlink() {
    if (typeof (window.open) == "function") {
        window.open("http://www.stackoverflow.com");
    }
    else {
        window.location.href = "http://www.stackoverflow.com";
    }
}

Since Internet Explorer don't like very much with window.location.href

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM