View Full Version : Pulling out hair: creating href link from string variable

10-22-2003, 04:50 AM
I've tried every possible combination except the right one obviously. I'm trying to create an href link out of a variable that contains a string address and use it in an email link with subject and body, etc. Please tell me what I'm doing wrong...
Something with the link method I think....

Assume the variable finalString already contains an http address.

document.write('<b><A CLASS="contact" HREF=\"mailto:\?subject\=Take a look at this page I found, ' + document.title + '?body=You can see this page at: ' + (link(finalString)) + '\" onMouseOver="window.status=\'Send this page to a friend!\'; return true" TITLE="Send this page to a friend!">Send this page to a friend!<\/A></b>');

10-22-2003, 06:01 AM
well there are a couple problems
first, what are all the \ s for those are unecisary
second, what is link() i doest appear to be any system function IE6
third, were you use ' for quoting something already inside single quotes (were u do the window.status)
also: its </a> not <\/a> and why isnt there a address to mailto and the TITLE propertie is unecisary

after fixing that you can get this

document.write('<b><a CLASS="contact" HREF="mailto:somebody@something.com?subject=Take a look at this page I found, ' + document.title + '?body=You can see this page at: ' + finalString + '" >Send this page to a friend!</a></b>');

if you wanted the status bar change, you would need to make a function that does that, that does not take any arguments

10-22-2003, 06:37 AM
When the email window opened, the body was empty (i was hoping to put the href link in there) and the subject was this:

Take a look at this page I found, Property Listings -?body=You can see this page at: undefined

10-22-2003, 10:18 PM
o i know why were i have ?body= it should be &body=

10-23-2003, 01:01 AM
please tell me how i can append the string: "&xm=on&ppinc=detail"
to the variable named finalString below, within the syntax below. finalString contains part of an http address but isn't complete without the rest of the string on the end. I can't seem to get the quotes right! (i know, duh...)
thank you very much,

document.write('<b><a CLASS="contact" HREF="mailto:?subject=Take a look at this property I found! '
+ '&body=You can see this property at: ' + finalString + ' " >Send this page to a friend!</a></b>');

10-23-2003, 05:57 AM
im not quite sure what u mean, but do u want to add the string "&xm=on&ppinc=detail" to finalstring?... ud just do finalString = finalString + "&xm=on&ppinc=detail"

10-23-2003, 06:20 AM
youre very patient, thank you for returning.
that's pretty much it - i want to append that weird string but in the document.write statement. believe it or not, the finalString actually contains that weird string but for some reason it's not appearing in the href link inside the email. i tested it by printing it on the page just before the Send This Page To a Friend link and then again right after, and the finalString prints exactly as I need it. Yet when I click on the Send This Page link and Outlook opens, the body contains the href link MINUS that weird portion! I can't figure it out. Here's the link - you can see for yourself.


click on one of the home categories, and look at a Details page and you'll see the Send This Link to a Friend.


10-23-2003, 02:40 PM
This is really nothing more than a guess, but you should be able to use the Unicode character code.

finalString += '\u0026xm=on\u0026ppinc=detail';

Give that a shot and see what happens.

10-23-2003, 03:41 PM
I tried to append it after the finalString but it won't add it to the link in the final output. This is baffling! What's really strange though, is that the variable finalString contains exactly the href that i need (through my parsing it) and i tested this - but when it prints inside the email body, it's missing the weird portion.

so for anybody that wants a brain teaser - here it is: how to append the string "&xm=on&ppinc=detail" onto the variable finalString and make it part of the finalString href.

document.write('<b><a CLASS= "contact" HREF="mailto:?subject=Take a look at this property I found! ' + '&body=You can see this property at: ' + finalString +'&xm=on&ppinc=detail' +' " >Send this page to a friend!</a></b>');}

10-24-2003, 06:48 AM
whenever you're putting querystrings in the url and you expect special characters in it, you should always encode it.

var subject = escape("Take a look at this property I found!");
var body = escape("You can see this property at: " + finalString + "&xm=on&ppinc=detail");
document.write('<b><a CLASS= "contact" HREF="mailto:?subject=' +subject + '&body=' + body + '">Send this page to a friend!</a></b>');

10-24-2003, 07:46 PM
glenn - your solution worked!
wow - this has been a great lesson for me...
thanks a lot and thanks to everyone else who responded too...
maybe someday i can post a reply to one of these questions!