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

javascript - How to convert signs in urltext to hex characters? (converting = to %3D) - Stack Overflow

programmeradmin3浏览0评论

With the script I'm making, jquery is getting vars from url parameter. The value that its getting is an url so if its something like

http://localhost/index.html?url=.php?something=some

it reads:

url = .php?something

If its like

http://localhost/index.html?url=.php?something%3Dsome

it reads:

url = .php?something%3Dsome

which would register as a valid url. my question is how can I search for = sign in the url variable and replace it with hex %3D with jquery or javascript?

With the script I'm making, jquery is getting vars from url parameter. The value that its getting is an url so if its something like

http://localhost/index.html?url=http://www.example./index.php?something=some

it reads:

url = http://www.example./index.php?something

If its like

http://localhost/index.html?url=http://www.example./index.php?something%3Dsome

it reads:

url = http://www.example./index.php?something%3Dsome

which would register as a valid url. my question is how can I search for = sign in the url variable and replace it with hex %3D with jquery or javascript?

Share Improve this question asked Jul 8, 2011 at 13:08 ArdaArda 10.9k13 gold badges42 silver badges54 bronze badges 1
  • How are you creating this URL? You should escape the whole url value. – Felix Kling Commented Jul 8, 2011 at 13:12
Add a ment  | 

2 Answers 2

Reset to default 5

Use the (built-in) encodeURIComponent() function:

url = 'http://localhost/index.html?url=' +
    encodeURIComponent('http://www.example./index.php?something=some');

Are you looking for encodeURIComponent and decodeURIComponent?

发布评论

评论列表(0)

  1. 暂无评论