Reputation: 1
How can I remove spaces (%20
's) from the following code?
var newTab = {"url": config.searchEngines[newTabIndex].url.replace(new RegExp("%s", "g"), info.selectionText).replace(new RegExp("%S", "g"), info.selectionText)}
selectionText
is a phone number that is highlighted on a web page. Obviously adding 20
to the number causes the number to become incorrect.
Upvotes: 0
Views: 94
Reputation: 7069
Check out the decodeURIComponent()
Function
http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp
var uri = config.searchEngines[newTabIndex].url,
newTab = {"url": decodeURIComponent(uri)};
Upvotes: 2
Reputation: 7426
Use this instead
str=str.replace(/%20/g,"")
so for your code
var newTab = {"url": config.searchEngines[newTabIndex].url.replace("%20", ""), info.selectionText).replace(/%20/g,""), info.selectionText)}
Upvotes: 0
Reputation: 8340
Just remove spaces instead of replacing with %20
, unless they are part of a string or after var
.
Upvotes: 0