在网址中转义特殊字符 [英] escaping special character in a url
问题描述
我正在使用网址打开一个html页面,我正在使用页面网址以查询字符串形式发送数据。
I am using a url to open a html page, and i am sending data in querystring withe the page url.
例如: abc.html?firstParameter = firstvalue& seconedParameter = seconedvalue
问题是如果 firstvalue
或 secondvalue
in参数包含
特殊字符,如#,(,),%,{
,然后我的网址构建不好。在这种情况下,url无法验证。
我在 javascript
中完成所有这些操作。
任何人都可以帮我解决这个问题。
Problem is that if firstvalue
or secondvalue
in parameter contains
special character like #,(,),%,{
, then my url is not constructing well. In this case url is not validating.
I am doing all this in javascript
.
Can any body please help me out this.
推荐答案
你有3个选择:
escape() will not encode: @*/+
encodeURI() will not encode: ~!@#$&*()=:/,;?+'
encodeURIComponent() will not encode: ~!*()'
但是在你的情况下,如果你想将url传递给其他页面的GET参数,你应该使用escape或encodeURIComponent,但不能使用encodeURI。
But in your case, if you want to pass a url into a GET parameter of other page, you should use escape or encodeURIComponent, but not encodeURI.
这篇关于在网址中转义特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!