Solved

Problem with Javascript encodeURI in Chrome extension

Posted on 2010-11-23
2
490 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

685 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