Search code examples
javascripthtmlhrefencodearabic

Getting `document.location.href` with Arabic letters


The problem is that I don't get the document.location.href in Arabic letters.

I get it as

/cat/%D9%81%D8%B9%D8%A7%D9%84%D9%8A%D8%A7%D8%AA

instead of:

/cat/فعاليات

I'm trying to get the page url and compare it to a list of menu items, so I can determine which item to select.

I'm trying this:

var url = document.location.href;

if(url.indexOf('blablabla') > 0 )
{
  ...
}

instead of 'blablabla' there will be some Arabic text.

Help Please! Thank you


Solution

  • You can use the decodeURIComponent it decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.