How to set “default” value for history.pushState a

2019-02-28 08:09发布

问题:

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;