Solved

Problem with Javascript encodeURI in Chrome extension

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

816 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

11 Experts available now in Live!

Get 1:1 Help Now