在 Safari 中 replaceState
will be called more than 100 times ,它会抛出:
SecurityError: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
更多信息:https://forums.developer.apple.com/thread/36650
我的问题是,在某些特定情况下,我会在用户滚动时更改 URL(使用 $(window).scroll(function() {...
。正如您可能猜到的那样,我到达了在 2 秒内限制为 100。
history.replaceState({}, '', newStringWithURLToUpdateInClientBrowser);
有什么解决方法吗?允许管理 history
的现有库可以解决这个问题吗?
所有其他浏览器不受此问题的影响。只有 Webkit。 这是查看错误的 fiddle :https://jsfiddle.net/j1sxxLwy/
在 Chrome 中它会达到 100,但尝试在 Safari 中运行它。
最佳答案
您是否考虑过限制滚动事件?
例如:
var timer = null;
$( window ).scroll( function() {
clearTimeout( timer );
timer = setTimeout( function() {
history.replaceState( {}, '', newStringWithURLToUpdateInClientBrowser );
}, 1000 );
} );
干杯,劳尔
关于javascript - OS X 和 iOS Safari history.replaceState 限制抛出 SecurityError : DOM Exception 18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419867/