Forum Moderators: open

Message Too Old, No Replies

Javascript Mailto links, with GET variables

Cannot escape the AMPERSAND to build the query string

         

ryan_b83

3:44 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



Hello, I am trying to build a function that when it runs it opens a mailto link (default email client) with information filled in. Included in the information is a link with a query string. Everything works EXCEPT the '&' symbol in the query string.

function emailVForm(){

var subject = "Order Form";
var body_message = "Hi, "+name+"%0D%0DPlease find attached pdf proofs for your order.%0D%0D Bla bla bla, please click on this link.%0D%0D http://www.website.com/script.php?t=v&pc="+pc+"%0D%0DThanks,%0DRyan";

var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;

win = window.open(mailto_link,'emailWindow');
win.close();

}

It seems to work fine except once it gets to the '&' in the mail client it stops and dosn't write anymore text. I also tried replacing the '&' with a '&' and that also wouldn't work.

Any Ideas?

Thanks,
Ryan

rocknbil

6:03 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try encoding the ampersand as you have with everything else in the body? Methinks that may be the problem. :-)

RonPK

7:47 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just curious: why are you using window.open()? mailto: usually launches a new application, so I don't see the need to open a new browser window.

kaled

10:32 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not all email clients accept body text (or they didn't when I tried something like this some years ago). You could try this...

1) Create a form.
2) Place a hidden input in the form.
3) Set the text of the hidden input as required.
4) Set the action of the form to mailto:whatever@...
5) submit the form.

I think you can specify the email subject in the form action but it's a long time since I tried this.

The downside of this aproach is that the text is preceded by fieldname=.

I'm not sure that using %0D is the best way to specify a line break. You should probably use \n to ensure platform independence but, again, it's a long time since I've tried this.

Kaled.

RonPK

8:12 am on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're after 100% platform independence, mailto: should not be used at all. I've seen plenty of PCs with messed-up registries or browser settings where nothing happens when the user clicks a mailto:-link. Server-side forms are more reliable.

ryan_b83

4:42 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



I don't want to be doing server side emailing. The reason is to make the client open a new email message with prefilled information...

i also tried this and it didn't work...


.../proof_approval.php?t=v"+String.fromCharCode(38)+"pc="+pc+"%0D%0DThank...

inveni0

7:26 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



It cuts out because it thinks the information after the '&' is a new variable.

What do you get when you print the value of body_message to a webpage? You may have to venture into PHP or ASP to work around this.

In the meantime, maybe all you smarties out there that think mailto: is a bad idea can actually prove they know something about this and help him with a fix?

[edited by: inveni0 at 7:33 pm (utc) on Oct. 19, 2006]

rocknbil

7:29 pm on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


No I meant just hex encoding. It's worth a shot.

var body_message = "Hi, "+name+"%0D%0DPlease find attached pdf proofs for your order.%0D%0D Bla bla bla, please click on this link.%0D%0D http://www.website.com/script.php?t=v%26pc="+pc+"%0D%0DThanks,%0DRyan";

%26 = &

inveni0

8:03 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



Just an idea, you could write the URL like this:

[website.com...]

Then, on the page that's doing the loading, you can have code that will split the 'c' variable into the 't' and 'pc' variables you require at the '.'

Just an idea if nothing else pans out.

ryan_b83

8:10 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



WORKED!

Thanks!
Ryan

inveni0

9:01 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



Which worked?

(I have a PHP site that has this same issue--it was a freebie for a church, so fixing it is on the back burner.)

ryan_b83

2:31 pm on Oct 20, 2006 (gmt 0)

10+ Year Member



This one worked as a replacemtn for the &


%26 = &

inveni0

5:13 pm on Oct 20, 2006 (gmt 0)

10+ Year Member



Wel that stinks, cause that doesn't work for me...guess I'll have to dig deeper.

Thanks.