如何确定浏览器是否支持 js pushState 函数
How to determine if browser is supporting js pushState function?
我想通过js脚本使用动态URL更新:
window.history.pushState("string", "Title", "/new-url");
但是,如果浏览器是旧的并且不支持此功能,它应该简单地重定向到新的URL。
有没有简单的方法来检查它?
您只需检查:
if (history.pushState) {
}
最简单(也是性能最高的):
if ('history' in window && 'pushState' in history) { // available
不过,我还是建议使用一些既定的历史记录管理解决方案,例如历史记录.js。
try {
window.history.pushState("string", "Title", "/new-url");
} catch ( e ) {
window.location = "/new-url";
}
if(!!history && !!history.pushState){
//browsers which support history and history's push state method
}
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- Backbone.js路由器混淆(pushState:true,尾部斜杠)
- 将当前 js 对象保存在 history.pushState 中
- 在 angular 上使用 HTML5 pushstate.js
- Backbone js pushState 给出无法获取错误
- 完全禁用Backbone.js哈希,但将pushState保留在历史记录中
- Backbone.js and pushState
- js在使用history.pushstate后设置默认url
- 使用node.js express服务器计算Backbone.js pushState路由
- 使用JS pushstate更改URL后的PHP_GET
- pushState阻止Backbone.js路由工作
- HTML5 pushState与Backbone.js路由器不工作在特定的服务器,但工作在其他
- Backbone.js的pushState不工作,并给出404错误
- Pushstate在backbone.js中不能正常工作
- JS:历史.pushState不能正常工作
- 使用pushState为backbone.js应用程序提供S3 web托管
- 使用pushState为backbone.js应用程序提供S3 web托管
- 如何确定浏览器是否支持 js pushState 函数
- 让主干路由与pushstate和node.js/express一起工作