Home  >  Article  >  Web Front-end  >  How to prevent Chinese parameters from being garbled when passing parameters in html? _html/css_WEB-ITnose

How to prevent Chinese parameters from being garbled when passing parameters in html? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:15:571086browse

I now need to use the parameter transfer between two html pages, in a.html

becomes a percent sign or something in b.html, and everything is messed up. Is there any way to prevent the Chinese from being garbled? Waiting online! !


Reply to the discussion (solution)

Convert Chinese using urlencode first

Convert Chinese using urlencode first

How to convert, can you give me An example?

<script> <br> document.write("<a href='b.html?addr=" encodeURIComponent("Shanghai City") "&b=" encodeURIComponent("Boxia Road") "'>aaaaaa</a>"); <br> </script>

In js, escape("XXX") is used for character encoding, and unescape("XXX") is used for decoding.

The method on the 4th floor is no longer recommended. Use the method on the 3rd floor.

<script> <br> document.write("<a href='b.html?addr=" encodeURIComponent ("Shanghai City") "&b=" encodeURIComponent("Boxia Road") "'>aaaaaa</a>"); <br> </script>

Go to another page When the second page receives the values, do they all become %%%? ?

var url=document.location.href;
var sub1=url.substring(url.indexOf("=") 1,url.indexOf("&"));
var sub2 =url.substring(url.lastIndexOf("=") 1);
alert("sub1:" sub1 " sub2:" sub2);

Both sub1 and sub2 are 100% consistent, What I want is that it can display Chinese

I already know, just use decodeURIComponent(sub1) to decode it, thank you very much 3lz for the example! ! !

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