gpt4 book ai didi

uiwebview - 如何修复 iOS9 UIWebview 中的 window.location 问题

转载 作者:行者123 更新时间:2023-12-04 22:58:53 25 4
gpt4 key购买 nike

自 iOS9 发布以来,我的 Web 应用程序不再运行。
自 iOS9 以来,该应用程序使用基于 url 哈希的导航和路由更改触发器,以不可预测的方式触发。

我做了很多研究,发现了IOS9 UIWebview中window.location的管理问题。

与这篇文章相关,angular 社区似乎已经通过发布的 angular.js 补丁修复了这个问题。

https://gist.github.com/IgorMinar/863acd413e3925bf282c

该问题已确定为:
iOS9 UIWebview 在使用 window.location 时不会同步更新 href

我在 IOS9 中查看了他们的更正,但我没有找到一种方法来重现他们的更正以使其适用于任何(非角度)webapp。

https://github.com/angular/angular.js/commit/8d39bd8abf423517b5bff70137c2a29e32bff76d#otherHash
https://github.com//petebacondarwin/angular.js/commit/47f16f35c213dbb165567102231ac1496246c456
https://github.com//angular/angular.js/blob/master/src/ng/browser.js

是否有人找到或正在研究使角度解决方案在任何(非角度)网络应用程序中工作的解决方案?

更新:

这是我正在调用的那种链接

domain/player/index.html

然后
domain/player/index.html#/online/presentation/ru1XA0nkvgHm/slide/0


[self.view stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.href = '#/offline/presentation/%@/slide/%ld?isNativeApp=1%@%@'",moduleId,(long)slideNumber,infoIcons,testingMode]]);

我做了测试,发现了一些奇怪的东西。

如果我使用最后一个命令进行两次调用,则第二次触发 hashchange 事件。

我不想将应用程序重新提交到应用程序商店,我想修改我的 html(可以从服务器获取)以检测哈希更改并使应用程序工作。

最佳答案

问题是这个特定的浏览器没有更新 window.location.href 的值。直到 JavaScript 事件循环的下一次运行。这意味着,如果您写入该值,然后立即将其读回,您会得到一个不同的值:

console.log(window.location.href)   // -> http://my.domain.com/path/to/page
window.location.href = 'http://my.domain.com/path/to/other/page';
console.log(window.location.href) // -> http://my.domain.com/path/to/page

// next tick of the event loop

console.log(window.location.href) // -> http://my.domain.com/path/to/other/page

注意第二个 console.log返回旧值,而不是新值。当前事件循环完成后,更新该值,如第三个 console.log 所示。 .

我们提出的解决方法是缓存我们写入的值,如果浏览器没有同步更新,然后从那时起使用该值,而不是从 window.location.href 返回的值。 , 直到有一个 hashchange 事件,它告诉我们浏览器终于​​自己整理好了。

以下是 AngularJS 中已修复的提交的链接: https://github.com/angular/angular.js/commit/8d39bd8abf423517b5bff70137c2a29e32bff76d

关于uiwebview - 如何修复 iOS9 UIWebview 中的 window.location 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719631/

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