admin管理员组

文章数量:1389783

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 pare 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

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 pare 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

Share Improve this question edited Jan 20, 2019 at 22:28 Salim Mahboubi 5798 silver badges26 bronze badges asked Jan 29, 2013 at 13:24 HasanAboShallyHasanAboShally 18.7k9 gold badges31 silver badges35 bronze badges 6
  • in the urls everything is by default url_encod(); your only option is to replace 'blablabla' with <?php echo url_encode('ARABIC_TEXT'); ?> I think it will do the trick – DaGhostman Dimitrov Commented Jan 29, 2013 at 13:26
  • 1 Thanks for the fast replay, I'm not using php.. any other ideas ? – HasanAboShally Commented Jan 29, 2013 at 13:28
  • 1 Why are you using Arabic letters to name your folders instead of latin-character transcripts? For example use events instead of فعاليات. And then your content to be in Arabic. I think even if you fix this here now, you will have more problems in the future. – Dimitris Damilos Commented Jan 29, 2013 at 13:28
  • actually im using asp routing, i get all the data from the database.. i just wanted it to be easy for the users.. so they can access the links directly. – HasanAboShally Commented Jan 29, 2013 at 13:30
  • Is there a public URL we can see this problem on? (It doesn't have to be the one you're working on, just one with Arabic characters in it.) – Paul D. Waite Commented Jan 29, 2013 at 13:31
 |  Show 1 more ment

2 Answers 2

Reset to default 5

You have to use decodeURIComponent(url);

Check this fiddle: http://jsfiddle/7spmF/

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

本文标签: javascriptGetting documentlocationhref with Arabic lettersStack Overflow