Convert URL parameters  to UTF-8 encoding?

Posted on 2007-07-25
Last Modified: 2010-02-24

I need some help to encode a url from Chinese characters to one which is universal.
As an example the URL would be: CHARACTERS HERE 001.JPG

It wont allow me to post the exact url here beacuse the Chinese characters arent recognized but you should get the idea

This script here:
Is nearly perfect:

when you enter: CHARACTERS HERE 001.JPG
it returns:

However the code on this script relies on an external .js file and i need it all in one document, e.g. using javascript tags in the header
<script type="text/javascript">

Also this script converts the "http://" to "http%3A//" which is not correct...

So can some kind person please post a full code example of how i convert the external .js file to be in the html header between the javascript tags and add in some code to stop the http at the beginning being converted.

Many thanks in advance.
Question by:whiteboyracer48
    LVL 8

    Accepted Solution

    You can have the external .js in the same code. Open the .js and copy the code inside the curreent page. Without the .js code I cannot help you.

    Expert Comment

    The answer is so much simpler that it looks. There is already a Javascript function that does de job for you, although it converts the ":" to "%3A, but you can convert it back by replacing it inside the original string:
    <script language="javascript">
    function URLcode(str){
    for testing purposes:
    alert(URLcode("!#*=Hello Everybody"));

    And, UTF-8 is a way of coding a Unicode Wide character. URLEncode is a way to encode a byte in a hexadecimal manner. UTF-8 and URL coding are not the same from far.

    Featured Post

    Live - One-on-One JavaScript Help from Top Experts

    Solve your toughest problems, fast.
    JavaScript experts are online now and ready to help you.

    Join & Write a Comment

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now