I want to implement a polyvore share button into a shopping cart. Some variable values are not being passed when the script executes (description and price) and I was told that URL encoding could be a solution. Can anyone share any leads on how to apply it in JavaScript alone to my snippet? Thanks in advance.
<a href="http://www.polyvore.com/cgi/add?title=%%GLOBAL_ProductName%%&url=http://lilaboutique.co.uk/products/%%GLOBAL_ProductName%%&imgurl=%%GLOBAL_ThumbImageURL%%&desc=%%GLOBAL_ProductDesc%%&price=%%GLOBAL_ProductPrice%%">
<img src="http://cdn.polyvore.com/rsrc/img/favicon.png"></a> 
 
 bakkal
 
 55.6k12 gold badges136 silver badges113 bronze badges
 
 - 
 2See: stackoverflow.com/questions/332872/…gen_Eric– gen_Eric2010年08月13日 13:25:36 +00:00Commented Aug 13, 2010 at 13:25
 
3 Answers 3
You can use encodeURIComponent to encode the specific querystring values.
var url = "http://www.polyvore.com/cgi/add?title=" 
 + encodeURIComponent('%%GLOBAL_ProductName%%') 
 + "&url=" + encodeURIComponent("http://lilaboutique.co.uk/products/" 
 + encodeURIComponent('%%GLOBAL_ProductName%%') 
 + "&imgurl=" + encodeURIComponent('%%GLOBAL_ThumbImageURL%%') 
 + "&desc=" + encodeURIComponent('%%GLOBAL_ProductDesc%%') 
 + "&price=" + encodeURIComponent('%%GLOBAL_ProductPrice%%'));
 
 answered Aug 13, 2010 at 13:26
 
 
 
 Brian Dukes 
 
 157k25 gold badges152 silver badges176 bronze badges
 
 
 Sign up to request clarification or add additional context in comments.
 
 
 
 6 Comments
elramirez
 var url = "polyvore.com/cgi/add?title=" + encodeURIComponent(%%GLOBAL_ProductName%%) + "&url=" + encodeURIComponent("lilaboutique.co.uk/products" + encodeURIComponent(%%GLOBAL_ProductName%%) + "&imgurl=" + encodeURIComponent(%%GLOBAL_ThumbImageURL%%) + "&desc=" + encodeURIComponent(%%GLOBAL_ProductDesc%%) + "&price=" + encodeURIComponent(%%GLOBAL_ProductPrice%%)); var img = "<img src="cdn.polyvore.com/rsrc/img/favicon.png">"; document.write(img.link(url));
  elramirez
 the above does not render the snippet. What am I doing wrong implementing your variable? THanks for the help.
  Brian Dukes
 First, I'm assuming that the values in 
  %% are getting replaced before we get here. You'll probably need to wrap this in quotes so that they're actually strings that you're encoding. Secondly, your method for creating the image and wrapping it in a link isn't going to work. I would suggest having the <a><img/></a> structure that you had before, then find the <a> (via document.getElementById, jQuery selector, etc) and update its href attribute to the url that you create.Brian Dukes
 Also, you'll need to make sure that the 
  %% values don't have quotes in them, so that you can successfully quote them in JavaScript...elramirez
 My main limitation is that this is a served template system (bigcommerce) to which I have no access to server side scripts, so mostly have been guess work to my best knowledge trying to figure out the corresponding variables needed to add the polyvore share button. The variables that I have used render the proper content that I need for the script but now how to make it work with the share button has been another story.
   | 
 i use this library they have a lot of good things including the urlencode
 answered Aug 13, 2010 at 13:25
 
 
 
 pleasedontbelong 
 
 20.1k12 gold badges55 silver badges79 bronze badges
 
 Comments
See escape() and unescape().
To remove "%", you can do this:
"http://www.polyvore.com/cgi/add?title=%%GLOBAL_ProductName%%&url".replace(/%/g, "")
 
 answered Aug 13, 2010 at 13:25
 
 
 
 Topera 
 
 12.4k15 gold badges71 silver badges105 bronze badges
 
 Comments
lang-js