In a page encoded with UTF-8, the URL encoded by the ASP built-in object Server.URLEncode () is not able to locate the file correctly, and the solution is to encode it using the JavaScript escape () function.
<% @LANGUAGE = "JAVASCRIPT" codepage= "65001"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Untitled Document </title>
<body>
<%
Response.Write ("server object output <br/>");
Response.Write (Server.URLEncode ("ether.エーテル.gif"));
Response.Write ("<br/>");
Response.Write ("javascript function Encodeurl output <br/>");
Response.Write (encodeURI ("ether.エーテル.gif"));
Response.Write ("<br/>");
Response.Write ("JavaScript function escape output <br/>");
Response.Write (Escape ("ether.エーテル.gif"));
%>
</body>
JavaScript version
<script type= "Text/javascript" > document.write (encodeURI ("ether.エーテル.gif")); document.write ("<br>"); document.write (Escape ("ether.エーテル.gif")); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Escape () Method:
The specified string is encoded using the ISO Latin character set. All spaces, punctuation, special characters, and other non-ASCII characters will be converted into%XX-formatted character encodings (XX equals the encoded 16 digits of the character in the character set table). For example, spaces's corresponding encoding is%20.
Characters that will not be encoded by this method: @ */+
encodeURI () Method:
Converts the URI string into a string in escape format using the UTF-8 encoding format.
Characters that will not be encoded by this method:! @ # $& * () =:/;? + '
encodeURIComponent () Method:
Converts the URI string into a string in escape format using the UTF-8 encoding format. This method encodes more characters than encodeURI (), such as/or characters. So if a string contains several parts of the URI, this method cannot be encoded, otherwise the URL will display an error after the/character is encoded.
Characters that will not be encoded by this method:! * ( ) '
Therefore, for Chinese strings, you only need to use escape if you do not want to convert the string encoding format into a UTF-8 format (such as when the original page and the target page charset are consistent). If your page is GB2312 or other code, and the page that accepts the parameter is UTF-8 encoded, you should use encodeURI or encodeuricomponent.
In addition, Encodeuri/encodeuricomponent was introduced after javascript1.5, and escape was in the javascript1.0 version.