Home  >  Article  >  Web Front-end  >  How to implement JS filtering special characters in url parameters_javascript skills

How to implement JS filtering special characters in url parameters_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:241345browse

There are some special characters in the URL transmission parameters, and these symbols cannot be passed directly in the URL. If you want to pass these special symbols in the URL, then their encoding must be used.
The following table lists some URL special symbols and encoded hexadecimal values ​​
1. URL medium means space +
2. Space spaces in URL can be represented by numbers or encoding
3. / Separates directories and subdirectories/
4. ? Separates actual URLs and parameters?
5. % specifies special characters %
6. # represents bookmarks #
7. & in URL The delimiter between specified parameters &
8. = The value of the specified parameter in the URL =

Solution:
replace() method If you directly use str.replace("-","!"), it will only replace the first matching character .
And str.replace(/-/g,"!") can replace all matching characters (g is a global flag).

replace()

The replacement character variables in js are as follows:
data2=data2.replace(/%/g,"%");
data2=data2.replace(/#/g," #");
data2=data2.replace(/&/g,"&");

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn