0

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
asked Aug 13, 2010 at 13:21
1

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

6 Comments

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));
the above does not render the snippet. What am I doing wrong implementing your variable? THanks for the help.
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.
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...
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.
|
0

i use this library they have a lot of good things including the urlencode

answered Aug 13, 2010 at 13:25

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.