[英]inconsistent window.history.pushState uri encoding
Take url address www.somesite.com/@user1
采取网址地址
www.somesite.com/@user1
If I click on a good old fashioned <a href...
hyperlink containing the link then the @
is percent encoded to %40
in the address bar. 如果单击包含链接的老式
<a href...
超链接,则@
在地址栏中的百分比编码为%40
。
If I use html5's window.history.pushstate("object or string", "Title", 'www.somesite.com/@user1')
the @
is not endocded - it instead shows as a '@' character. 如果我使用html5的
window.history.pushstate("object or string", "Title", 'www.somesite.com/@user1')
,则不会插入@
-而是显示为'@'字符。
This inconsistency troubles me. 这种矛盾困扰着我。 Mayhaps there is a way to make the behaviour consistent?
也许有一种方法可以使行为保持一致?
I have considered encodeURIComponent('www.somesite.com/@user1')
for the pushstate url, but this also encodes the '/', and what I am hoping is for the <a href...
hyperlink not encode the '@' symbol. 我已经考虑了pushURI网址的
encodeURIComponent('www.somesite.com/@user1')
,但这也对'/'进行了编码,而我希望的是<a href...
超链接而不是对'@进行编码'符号。
Using encodeURIComponent makes javascript assume there are no special HTTP characters to ignore. 使用encodeURIComponent可使javascript假定没有特殊的HTTP字符要忽略。 extract the compnenet first:
首先提取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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.