Question about using JS scripts to call urlencode in the Link

Source: Internet
Author: User

Today, I wrote the following section in the Code:

<Script
Language = "JavaScript" type = "text/JavaScript">
<! --

Function play (URL)

{

// Alert (URL );

VaR RTN = showmodaldialog ("playmovies. aspx? Url = "+ URL, window,
"Dialogwidth: 640px; dialogheight: 480px; Status: 0;
Help: 0; scroll: 0 ;");

}
// -->
</SCRIPT>
<
Href = 'javascript: Play ("<% # server. urlencode (eval (" FILENAME "). tostring () %>"); '> watch online </a>


The code is very simple and can be run in real time (when the file name is Chinese or non-ASCII characters), it is always not running properly. Debug and view the source file. After comparison, it is found that the escape is correct, but alert is not correct in the script. Correct after changing the code to the following:

<
Onclick = 'javascript: Play ("<% # server. urlencode (eval (" FILENAME "). tostring () %> ");'
Href = "#"> watch online </a>


In fact, it hasn't changed much, and I haven't thought too much about writing code. I think it's because the browser itself has converted itself when processing something in href (the browser has used the Utf-8 to send a URL request. The strange thing is why the conversion is incorrect, or the JavaScript code is inconsistent with the browser ).


Although the problem is simple, record it. For future reference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.