如何设置“默认” history.pushState和replaceState的值? [英] How to set "default" value for history.pushState and replaceState?

查看:178
本文介绍了如何设置“默认” history.pushState和replaceState的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用 title param的浏览器,我们应该使用什么值来告诉浏览器使用其默认值?



在Safari 5.1.7(7534.57.2) 中,如果我将 null c> $ 作为 title param,它使用浏览器默认值:



img src =https://i.stack.imgur.com/dFnjh.pngalt =enter image description here>



但是,Opera 12.16 分别使用字符串nullundefined



>

$



在Opera上,我们如何设置为defaultif nullundefined无效?



MDN的历史 docs 似乎没有太多关于 History.pushState / replaceState 的允许值的信息s参数。)

解决方案

不确定是否有一种将其设置为默认标题的具体方法,应该在所有浏览器中工作的标题设置为 location.href

  document.title = location.href; 


For browsers that use the title param, what value should we use to tell the browser to use its default?

In Safari 5.1.7 (7534.57.2), if I put null or undefined as the title param, it uses the browser default:

However, Opera 12.16 uses the string "null" and "undefined" respectively:

What's supposed to be the "correct" behavior?

On Opera, how can we set to "default" if "null" and "undefined" doesn't work?

(MDN's History docs doesn't seem to have much info regarding the allowed values for History.pushState/replaceState's parameters.)

解决方案

Not sure if there is a specific way of setting it to a default title, but a safe way which should work in all browsers is setting the title to the location.href

document.title = location.href;

这篇关于如何设置“默认” history.pushState和replaceState的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆