gpt4 book ai didi

ios - window.location.href 不适用于 url 方案

转载 作者:可可西里 更新时间:2023-11-01 05:33:59 26 4
gpt4 key购买 nike

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

在 iOS 7 中,按钮工作正常,我点击它,我的另一个 View Controller 打开了。但是在 iOS 8 中,当我点击按钮时什么也没有发生。我处理 url 操作的方法从未被调用。

网页正在使用 "window.location.href = MyUrlScheme://...",这在 iOS7 中同样可以完美运行,但在 iOS8 中却不行。

有什么想法吗?

最佳答案

您可能已经找到了这个问题的答案,但我会把我的解决方案留在这里,它可能会对某些人有所帮助。今天遇到这个问题,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

关于ios - window.location.href 不适用于 url 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27526966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com