【发布时间】:2016-10-31 05:21:28
【问题描述】:
在 iOS 的 Safari 中调用 history.pushState 后,在使用浏览器后退按钮变回时,无法再使用 alert()、confirm() 或 prompt()。
这是 iOS 错误吗?是否有任何已知的解决方法?
重现此行为的简单示例:
<html>
<body>
<ul>
<li>Step 1: <button onclick="alert(Math.random())">Confirm Alert is working</button></li>
<li>Step 2: <button onclick="history.pushState(null, null, '/debug/'+Math.random());">Change History</button></li>
<li>Step 3: use your browser back button, to go back</li>
<li>Step 4: <button onclick="alert(Math.random())">Alert is not working anymore</button></li>
</ul>
</body>
</html>
您可以在这里在线试用:goo.gl/faFW6o。
【问题讨论】:
-
@JacobHeater 不幸的是,它不是在独立运行时(没有 iframe)
-
@JacobHeater 我在描述中添加了一个现场演示。请随时在那里尝试一下。
-
您是否在 Safari iOS 上进行测试?
-
我用上面的复制步骤打开了 rdar://45141145。他们要求我提交系统诊断和问题视频,我刚刚完成了。
-
这是我的发现,一旦你使用 ios safari 后退按钮,我认为浏览器会从缓存中加载内容,因此 js 无法正常工作。而不是使用使用 window.history.go(-1) 的后退按钮。我试图检测后退按钮,但我失败了。另外尝试了这个,但它没有刷新。也许我错过了一些东西 window.onpageshow = function(event) { if (event.persisted) { window.location.reload() } };
标签: javascript ios mobile-safari back-button browser-history