我怎样才能'安全'使用window.history.pushState [英] How can I use window.history.pushState 'safely'
本文介绍了我怎样才能'安全'使用window.history.pushState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在支持浏览器时使用 window.history.pushState()
函数。不幸的是我在Firefox上遇到错误:
I would like to use the window.history.pushState()
function in supporting browsers. Unfortunately I'm getting an error on Firefox:
TypeError:history.pushState不是函数
TypeError: history.pushState is not a function
如何避免这种情况?
推荐答案
[尝试 - catch]标签意味着你已经知道了答案......(有什么更具体的吗?)
另一种可能性是检查 if(history.pushState)history.pushState({}, document.title,location.href);
[try-catch] tag implies what you know the answer already... (is there anything more specific?)
The other possibitity is to check if ( history.pushState ) history.pushState( {}, document.title, location.href );
这篇关于我怎样才能'安全'使用window.history.pushState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文