【问题标题】:window.open() does not work on iOS app using phone gapwindow.open() 不适用于使用电话间隙的 iOS 应用程序
【发布时间】:2012-08-02 17:19:06
【问题描述】:

我正在使用 Phonegap 编写一个 ios 应用程序, 我在我的应用程序中需要的只是当 phonegap 调用 index.html html 页面会将用户重定向到我的网站 问题是 html 不会将应用程序重定向到我的网站,我没有 关心电话间隙是否打开了 safari 我只需要它把它重定向到我的网站我的代码 是:

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

【问题讨论】:

    标签: javascript html ios cordova


    【解决方案1】:

    让你的函数看起来像这样:

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

    【讨论】:

      【解决方案2】:

      甚至更好

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

      由于 Internet Explorer 不太喜欢 window.location.href

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多