Chinese transcoding and carriage return replacement during link submission

Source: Internet
Author: User
Function printnotice (noticeid, template) {If (noticeid = ''| noticeid = 'null') {alert ('save it and try again. ');} Else {var noticeorgname =' $ {tasknoticesdto. agency} '; var noticeorgno =' $ {tasknoticesdto. taskno} '; var noticecontent = document. getelementbyid ("NOTE "). innerhtml. replace (/[\ r \ n]/g, "<br>"); var noticedate = '<s: Date name = "tasknoticesdto. decidedate "format =" yyyy-mm-dd "/> '; alert (noticecontent); var url =' $ {pagecontext. request. contextpath}/XXX/noticeview. JSP? Filetypeapps.doc & edittype = 1 & template = '+ template + 'your iceorgname =' + encodeuricomponent (noticeorgname) + 'your iceorgno = '+ noticeorgno + 'your icecontent =' + encodeuricomponent (noticecontent) + 'your icedate = '+ noticedate; window. open (URL, '_ blank ');}}

To another page, you also need to replace those with carriage returns.

    var noticeContent='<%=noticeContent   %>'.replace(/\<br>/g,"\r");

For transcoding submission, refer to the following:

  • JavaScript code involves three functions: Escape, encodeuri, and encodeuricomponent. The corresponding three decoding functions are: Unescape, decodeuri, and decodeuricomponent.

    1. encodeuricomponent is required when passing parameters so that the combined URL will not be truncated by special characters such.
    Example: <script language = "JavaScript"> document. Write ('<a href = "http://passport.baidu.com /? Logout & Aid = 7 & U = '+ encodeuricomponent ("http://cang.baidu.com/bruce42") +' "> exit </a & gt; '); </SCRIPT>

    2. encodeuri can be used for URL redirection.
    Example: location. href = "/encodeuri" ("http://cang.baidu.com/do/s? WORD = Baidu & Ct = 21 ");

    3. You can use escape when JS uses data.
    For example, search for the history record in the bucket.

    4. When encoding Unicode values other than 0-, escape outputs % u *** format. In other cases, escape, encodeuri, and encodeuricomponent have the same encoding result.

    The most commonly used format is encodeuricomponent, which converts special characters such as Chinese and Korean into UTF-8 URL encoding, therefore, if you want to use encodeuricomponent to transmit parameters to the backend, you must use backend decoding to support UTF-8 (the encoding method in form is the same as that on the current page)

    Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, A-Z, A-Z
    Encodeuri is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, A-Z, A-Z
    Encodeuricomponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, A-Z, A-Z

    According to the instructions, what I need is the encodeuricomponent function.

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.