Solved

Problem with Javascript encodeURI in Chrome extension

Posted on 2010-11-23
2
486 Views
Last Modified: 2012-05-10
I have the following Javascript Code in my Chrome extension:

--snip--
console.log("title: "+title);
console.log("body: "+body);
var s = encodeURI(title);
console.log("s: "+s);
--snip

The URL that the extension processes is: http://de.wikipedia.org/wiki/Robert_Louis_Stevenson
title is tab.title from the active tab.

The console output is:

title: Robert Louis Stevenson – Wikipedia
body: http://de.wikipedia.org/wiki/Robert_Louis_Stevenson
s: Robert%20Louis%20Stevenson%20%E2%80%93%20Wikipedia

My question is, why is the minus char "-" converted to %E2%80%93 in this case? What does this mean?

If I try the same code on a different URL, for example the same Wikipedia page in English instead of German: http://en.wikipedia.org/wiki/Robert_Louis_Stevenson

the output is like this:

title: Robert Louis Stevenson - Wikipedia, the free encyclopedia
body: http://en.wikipedia.org/wiki/Robert_Louis_Stevenson
s: Robert%20Louis%20Stevenson%20-%20Wikipedia,%20the%20free%20encyclopedia

This time the minus char "-" is not converted at all.

I guess it may have something to do with a Unicode convertion, but both these pages are encoded with UTF-8 according to the page sources.

So all in all I want to know the exact meaning why a minus char is converted to E2%80%93% in encodeURI().
0
Comment
Question by:dMa
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 34202993
In this case the - is no minus it's a long minuns (e.g in word the char you get if you type three -, or in html it's the entitiy –)
0
 
LVL 2

Author Comment

by:dMa
ID: 34203109
What is the difference between – and the ASCII - (code 45)? Why is it displayed as %E2%80%93, due to what convention?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

20 Experts available now in Live!

Get 1:1 Help Now