Firefox自动解码url中的编码参数,不会在IE中发生 [英] Firefox automatically decoding encoded parameter in url, does not happen in IE

查看:183
本文介绍了Firefox自动解码url中的编码参数,不会在IE中发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox和IE之间感到沮丧,主要是Firefox,因为它可以自动解码哈希中的参数,然后我可以在Javascript中使用它。 IE不会自动解码url,因此不会给我阅读错误。



我的问题类似于这个,除了我不使用ASP.NET ASP.NET MVC自动解码来自AJAX的JSON编码参数



所以如果我采取像 example.com/#question =!%的网址%40%23%24%25 ^%26 *(



而!%40%23%24%25 ^%26 *(使用encodeURIComponent编码,在IE访问哈希时将被保留为!%40%23%24%25 ^%26 *(但是在Firefox中,当我访问哈希时它会自动解码成!@#$%^& *(



这个问题是在我的脚本中,我使用decodeURIComponent解码编码的值,如果字符串确实被编码,这是很好的,因为它已经在Firefox中解码了给我一个格式错误的URI序列错误,IE不会给我任何错误。



我如何解决这个问题?

解决方案

搜索后我发现这是一个跨浏览器问题,最好使用 location.href.split(#)[1] 而不是 window.location.hash


I am having frustration between Firefox and IE, well mostly Firefox as it is automatically decoding a parameter in the hash before I can work with it in Javascript. IE does not automatically decode the url thus not giving me reading errors.

My problem is similar to this one except I am not using ASP.NET ASP.NET MVC automatically decoding JSON-encoded parameters from AJAX

So if I take a url like example.com/#question=!%40%23%24%25^%26*(

whereas the "!%40%23%24%25^%26*(" was encoded using encodeURIComponent, in IE when I access the hash it will be left as "!%40%23%24%25^%26*(", however in firefox, when I access the hash it is automatically decoded into "!@#$%^&*("

The problem with this is that in my script I am using decodeURIComponent to decode the encoded value, which is fine if the string is indeed encoded. Since it is already decoded in Firefox, it gives me a malformed URI sequence error, and IE does not give me any errors at all.

How can I fix this?

解决方案

After searching I found out that this is a cross browser problem, and it is better to use location.href.split("#")[1] instead of window.location.hash

这篇关于Firefox自动解码url中的编码参数,不会在IE中发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆