【问题标题】:window.location.href doesn't work with url schemewindow.location.href 不适用于 url 方案
【发布时间】:2014-12-17 13:44:31
【问题描述】:

我在 iOS 8 和 UIWebView 中遇到问题。我正在将一个应用程序运行到 webview 中,在这个应用程序中我有一个图标来调用特定的 url。这是像应用程序 url(url 方案)一样注册的 url。然后进入我的 UIWebView,当我按下按钮时,应该显示其他视图控制器。

在 iOS 7 中,该按钮工作正常,我点击它,我的另一个视图控制器已打开。但是在 iOS 8 中,当我点击按钮时什么也没有发生。我处理 url 操作的方法永远不会被调用。

网页使用"window.location.href = MyUrlScheme://...",这在iOS7中也能完美运行,但在iOS8中却不行。

有什么想法吗?

【问题讨论】:

    标签: ios uiwebview ios8 url-scheme


    【解决方案1】:

    您可能已经找到了这个问题的答案,但我将在此处留下我的解决方案,它可能会对某人有所帮助。今天遇到这个问题,iOS8 UIWebView 没有响应 window.location.href = "MyUrlScheme://do-something"...

    所以我在 html 页面中添加了一个 iframe,设置了 src 属性并删除了 iframe。

    var sendObjectMessage = function(parameters) {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('src', "MyUrlScheme://"+parameters);
        document.documentElement.appendChild(iframe);
        iframe.parentNode.removeChild(iframe);
        iframe = null;
    }
    
    sendObjectMessage("send-something");
    

    看看这个链接https://gist.github.com/irace/3688560

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 1970-01-01
      • 2023-01-18
      • 2014-08-28
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      相关资源
      最近更新 更多