window.history.pushState uri编码不一致
inconsistent window.history.pushState uri encoding
获取url地址www.somesite.com/@user1
如果我点击一个包含链接的老式<a href...
超链接,那么@
在地址栏中被百分比编码为%40
。
如果我使用html5的window.history.pushstate("object or string", "Title", 'www.somesite.com/@user1')
,则@
是而不是内插的,而是显示为"@"字符。
这种不一致性困扰着我。也许有办法让行为保持一致?
我已经考虑过将encodeURIComponent('www.somesite.com/@user1')
用于pushstate url,但这也编码了"/",我希望<a href...
超链接不编码"@"符号。
使用encodeURIComponent使javascript假设没有特殊的HTTP字符可以忽略。首先提取compnenet:
var url = "www.somesite.com/@user1";
var atPos = url.indexOf('@');
var urlComp= url.slice(atPos); //@user1
url = url.slice(0, atPos);
url += encodeURIComponent(urlComp); //"www.somesite.com/%40user1"
相关文章:
- 当属性不一致时,如何根据属性对JS对象列表进行排序
- Android和JavaScript解析API之间不一致
- Javascript的行为与PHP包含文件不一致
- 对这种与document.domain和CORS相关的不一致行为的解释是什么
- 点击链接行为不一致
- Passport.js`isAuthenticated()`不一致的行为;当它应该是真的时候是假的
- 与显示不一致
- Ext 4.2.1 模型日期解析在浏览器之间不一致
- 通过 Dropbox API 上传时的文件内容不一致
- JavaScript - 对象属性不一致
- Javascript 混淆了 null、instanceof 和 typeof 的语法不一致
- localeCompare 显示使用前导变音字符对单词进行排序时不一致的行为
- SVG 对象部分上的 JQuery click() 不一致
- 使用forEach和.shift()时结果不一致
- Window.open浏览器的高度不一致
- 不同浏览器中的LinkButton PageMethod行为不一致
- 谷歌地理编码不起作用
- 当活动处于后台时,Android WebView不一致
- 使用正则表达式删除标记时,Firefox和Chrome之间存在不一致
- window.history.pushState uri编码不一致