Page 1 of 2

Document write url

Posted: Wed Nov 11, 2009 6:04 am
by avoosh
I am trying to write a script that adds a dynamic link.
cgi/add?title=TITLE&url=URL&imgurl=IMAGE_URL">

using the code (below)

Code: Select all

<a href="javascript&#058;window.location = 'http://www.socialsite.com/cgi/add.php?
title='+encodeURIComponent( document.title)+'&
url='+encodeURIComponent (location.href);">
<img src="http://cdn.socialsite.com/rsrc/img/favicon.png">
</a><noscript><a href="http://www.socialsite.com">Social Bookmarking</a></noscript></a></noscript>
Below is the output. What is wrong with the above code?

&url=http%3A%2F%2Fwww.mywebsite.com%2Fname-of-link-looks-like-this.html

How would I also add a dynamic link to the image location?



Thank you in advance.

Re: Document write url

Posted: Wed Nov 11, 2009 7:14 am
by sergio-pro
Hi there

The link generated is OK.
These http%3A%2F%2F - are escaped values of http:// - which is done to separate the URL you are passing as a parameter from the link url itself.

To have a cleaner code, consider moving url construction to a function:

Code: Select all

 
<a href="#" onclick="handleImageClick();">
<img src="http://cdn.socialsite.com/rsrc/img/favicon.png">
</a>
 
<script type="text/javascript">
function handleImageClick() {
  var path = 'http://www.socialsite.com/cgi/add.php?';
  path += 'title=' + encodeURIComponent( document.title );
  path += '&url=' + encodeURIComponent ( location.href ); 
  document.location.href = path;
}
</script>
 
 

Re: Document write url

Posted: Wed Nov 11, 2009 7:57 am
by avoosh
Hi, Thank you.

How would I add the dynamic item image url to this.

path +=imageurl='+encodeURIComponent(document.location.href);

<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 +=imgurl='+encodeURIComponent(document.location.href);
document.location.href = path;
}
</script>

After that I need the link to open in a new window.

Thank you again for your help

Re: Document write url

Posted: Wed Nov 11, 2009 9:04 am
by sergio-pro
To make it open in a new window just add target="_blank" to "a" tag

Code: Select all

 
<a href="#" onclick="handleImageClick();" target="_blank">
 

Re: Document write url

Posted: Wed Nov 11, 2009 9:14 am
by avoosh
Strange, when I added the _blank code it opened a new window to the same page.

Code: Select all

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

Re: Document write url

Posted: Wed Nov 11, 2009 9:51 am
by sergio-pro
Oh, I see, then try this:

Code: Select all

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

Re: Document write url

Posted: Wed Nov 11, 2009 9:59 am
by avoosh
I'm sorry, yes it did, my fault

Re: Document write url

Posted: Wed Nov 11, 2009 10:13 am
by avoosh
The popup code worked perfect, thanks.

The last thing I need for this to work (hopefully) is the path to the image

&imgurl=http://dev.website.com/images/resized/8-iID_320x260.jpg

Code: Select all

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

Re: Document write url

Posted: Wed Nov 11, 2009 10:18 am
by sergio-pro
And what is the problem with them?
Do you want the image URL inside A tag to be in that param?

Re: Document write url

Posted: Wed Nov 11, 2009 10:36 am
by avoosh
the last part of the url is imgurl=http://www.website.com/resized/image.jpg

so I think the answer is yes. I apologize, I am learning and researched this all night but can not find any info on how to include a dynamic url to an image in the link

Re: Document write url

Posted: Wed Nov 11, 2009 10:39 am
by avoosh
This is the how the output of the code is supposed to look like

http://www.website.com&url=http://www.website.com/thisistheitemurl&imgurl=http://www.website.com/img/cw12900a.jpg

Thanks

:banghead:

Re: Document write url

Posted: Wed Nov 11, 2009 10:44 am
by sergio-pro
Dont understand what excatly do you mean,
but I guess it should be something like this :)
(passing image url as a handleImageClick function parameter )

Code: Select all

 
<a href="#" onclick="handleImageClick( 'http://cdn.socialsite.com/rsrc/img/favicon.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 ( imgUrl );
  window.open(path);
 }
 </script>
 

Re: Document write url

Posted: Wed Nov 11, 2009 11:02 am
by avoosh
The code needs to output to this

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

Re: Document write url

Posted: Wed Nov 11, 2009 11:06 am
by sergio-pro

Code: Select all

 
<a href="#" onclick="handleImageClick( 'http://cdn.socialsite.com/rsrc/img/favicon.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>
 
 
 
This one? :)

Re: Document write url

Posted: Wed Nov 11, 2009 11:18 am
by avoosh
I tried that but it didn't work. it outputs the the favicon instead of the item image.

<a href="#" onclick="handleImageClick( 'http://cdn.social.com/rsrc/img/favicon.png' ); return false;" target="_blank">
<img src="http://cdn.socialsite.com/rsrc/img/favicon.png">
</a>

<a href="http://www.website.com/cgi/add?title=TI ... avicon.png">

so close yet so far ... thank you for sticking with me on this.