How to set “default” value for history.pushState and replaceState?

风流意气都作罢 提交于 2019-12-02 11:01:15

问题


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.)


回答1:


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;


来源:https://stackoverflow.com/questions/26316325/how-to-set-default-value-for-history-pushstate-and-replacestate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!