如何设置“默认” history.pushState和replaceState的值?

编程入门 行业动态 更新时间:2024-10-20 05:24:47
本文介绍了如何设置“默认” history.pushState和replaceState的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

但是,Opera 12.16 分别使用字符串null和undefined

>

$

在Opera上,我们如何设置为defaultif null和undefined无效?

( 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的值?

本文发布于:2023-11-01 18:08:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   history   replaceState   pushState

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!