javascripturlwindow.locationpercent-encoding

Percent encoding in window.location


When I open a url with special characters using window.location, it seems to percent encode the special characters and then opens the URL. For example

var url = "http://gramfeed.com/instagram/tags/kühl";
window.location = url;

This will result in opening a page with URL:

http://gramfeed.com/instagram/tags/k%C3%BChl

instead of:

http://gramfeed.com/instagram/tags/kühl

How do I make the URL open correctly without percent encoded characters

Here is a jsfiddle to play with the code: http://jsfiddle.net/krisrak/aSkMR/


Solution

  • I do not believe the problem is with windows.location and your JavaScript. The problems is rather with how gramfeed.com interprets tags. Try this in your code:

    var url = "https://www.google.com/search?q=kühl"
    window.location = url;
    

    See that special characters stay unconverted.

    Now try typing http://gramfeed.com/instagram/tags/kühl directly in browser address bar - the URL gets converted.