如何让 Chrome 网址显示空格而不是 %20

如何让 Chrome 网址显示空格而不是 %20

像 Firefox 这样的浏览器会将包含空格(包括 )的 URL 显示为实际空格();Chrome在地址栏中始终将空格显示为%20(将 nbsp 显示为)。(即,Firefox在地址栏中显示 ,而 Chrome 显示。)有什么方法可以让 Chrome 将空格显示为而不是?%C2%A0http://example.com/A Bhttp://example.com/A%20B%20

答案1

如果您可以使用下划线代替空格(就像我的情况一样,我只需要提高 URL 的可读性),则可以使用:

window.history.pushState("string", "Title", window.location.href.replace(new URL(window.location.href, location).origin+'/', '').replaceAll('%20','_'))

(最后一个replaceAll可以是空格而不是下划线,但 Chrome 无论如何都会将其替换为 %20)

也许使用 Chrome 扩展程序可以做得更好。

相关内容