Page 1 of 1

encodeURIComponent pass to 2nd parameter help

Posted: Wed Nov 11, 2009 3:00 pm
by avoosh
I am trying to write a script that outputs the following url

<a href="http://www.socialsite.com/cgi/add?title ... =IMAGE_URL">
<img src="http://cdn.socialsite.com/rsrc/img/my_image.png">
</a>

The code below outputs a the url below. The problem is (in red text). It is passing the first parameter. I need it to pass tthe second (item image) image parameter. What do I need to change to pass the first image and output the item image url (2nd)

<a href="http://www.socialsite.com/cgi/add?title ... RL&imgurl=img/my_image.png">

Code: Select all

<a href="#" onclick="handleImageClick( 'http://cdn.socialsite.com/rsrc/img/my_image.png' ); return false;" target="_blank">
 <img src="http://cdn.socialsite.com/rsrc/img/favicon.png">
 </a>
  
 <script type="text/javascript">
 function handleImageClick( imgUrl ) {
   var path = 'http://www.socialsite.com/cgi/add.php?';
   path += 'title=' + encodeURIComponent( document.title );
   path += '&url=' + encodeURIComponent ( document.location.href );
   path += '&imgurl=' + encodeURIComponent ( imgUrl );
   window.open(path);
  }
  </script>
Thank you for your help

Re: encodeURIComponent pass to 2nd parameter help

Posted: Fri Nov 13, 2009 12:32 am
by avoosh
I am stumped on how to get the above code to pass through. Maybe I went about writing the code wrong. Is there a better way to output to a link with the following?

<a href="http://www.socialsite.com/cgi/add?title ... =IMAGE_URL">

I would appreciate any help on how to do this.

Re: encodeURIComponent pass to 2nd parameter help

Posted: Fri Nov 13, 2009 1:13 am
by avoosh
This is the static version of the output to link

<a href="http://www.socialwebsite.com/cgi/add?ti ... =IMAGE_URL">
<img src="http://cdn.socialwebsite.com/rsrc/img/favicon.png">
</a>

This is the code that I have so far that works (kind of). It will output the Title, the url of the item but not the url of the image.

Code: Select all

<a href="#" onclick="handleImageClick();" target="_blank">
<img src="http://cdn.polyvore.com/rsrc/img/favicon.png">
</a>
 
<script type="text/javascript">
function handleImageClick() {
var path = 'http://www.polyvore.com/cgi/add.php?';
path += 'title=' + encodeURIComponent( document.title );
path += '&url=' + encodeURIComponent ( location.href );
path += '&url=' + [color=#BF0000]image url (will not work[/color]
document.location.href = path;
 }
 </script>
Thank you for your help