最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - setting top.location.hash with %20 in firefox - Stack Overflow

programmeradmin0浏览0评论

In firefox, using this javascript:

top.location.hash = "#here%20are%20spaces";

changes the browser url to:

 are spaces

I expected firefox to show the encoded spaces as %20 in the browser url.

  1. What's going on here? Why is firefox not setting the url to the string as I passed it?
  2. How can I force firefox to update the url with the encoded characters?

and...

If I add set the url to

top.location.hash = "#here%20are%20spaces%";

It works(!?), albeit with an extra unwanted % appended to the end. I am not sure if this is a bug or a feature. Ideas or references on how to proceed?

In firefox, using this javascript:

top.location.hash = "#here%20are%20spaces";

changes the browser url to:

http://mysite./#here are spaces

I expected firefox to show the encoded spaces as %20 in the browser url.

  1. What's going on here? Why is firefox not setting the url to the string as I passed it?
  2. How can I force firefox to update the url with the encoded characters?

and...

If I add set the url to

top.location.hash = "#here%20are%20spaces%";

It works(!?), albeit with an extra unwanted % appended to the end. I am not sure if this is a bug or a feature. Ideas or references on how to proceed?

Share Improve this question asked Feb 16, 2009 at 4:40 jedierikbjedierikb 13.1k24 gold badges101 silver badges171 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

%20 are replaced with an empty space (in firefox 3) just for readability purpose. You shouldn't worry about it.

It still seems to be an active Firefox Bug for this issue (albeit reported for Firefox in Ubuntu, but also seen for other OS)....

Firefox displays the unencoded value in the location bar, as it does for all all URLs that contain encoded values. Try to go to some url with special characters, then cut & paste it to notepad/...

Have you tried if it works anyway and does what you want?

That's a security precaution. If it wasn't there, one could encode character that looks just like "a" in paypal. string inside your address bar.

发布评论

评论列表(0)

  1. 暂无评论