window.location.href

B

Brvsra

Javascript Experts,

I know very little about javascript and could use someone's help.

I have created a function to send an email, listed below is the function.
The function works fine, with one exception. When the function is passed,
the popup screen only displays the first part of the querystring.
The email address returns: http://server.something.asp?Test=1

Should return something like this:
http://server.something.asp?Test=1&Test2=2, Can someone tell me why its
doesn't return the complete querystring?

<script language="javascript">
function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " +
document.title;
mail_str += ". You can view it at, " + window.location.href;
window.location.href=mail_str;
}
</script>
 
S

sancha

Hi i am not that good in javascript but i faced a similar problem.
Maybe this will help.

var mail_str = "mailto:?subject="+encodeURIComponent("Check out the ")
+ encodeURIComponent(document.title);
mail_str += "&body="+encodeURIComponent("I thought you might be
interested in the ") +
encodeURIComponent(document.title);
mail_str += encodeURIComponent(". You can view it at, ") +
window.location.href;

i used the encodeURIComponent as encode decode has been deprecated in
javascript. Hope it helps
 
F

Fred Oz

sancha said:
Hi i am not that good in javascript but i faced a similar problem.
Maybe this will help.

A couple of hints:

1. You can't depend on the user having their e-mail client configured
to respond to the mailto: script.

2. Some clients have a limit on the size of mailto tag - Lotus Notes
only allows a string of 200 characters total.

3. The function call should return false to stop the form submitting,
otherwise re-loading the page in some browsers causes unexpected
results.

4. The document may not have a title (even though one is required by
the spec) so test and put in a meaningful string if it doesn't.

5. Concatenating the string is less efficient than joining an array,
but for a few lines of text, the difference is trivial, particularly
as starting up the e-mail client may cause perhaps 5 to 10 seconds
delay (or more).

A modified script is below:

<html>
<head><title>e-mail this page</title>
<script type="text/javascript">

function mailIt() {

// Make sure title is OK
var theTitle = (document.title)?"\""+document.title+"\"" : " this";

var mail_str = "mailto:?subject="
+ encodeURIComponent("Check out ")
+ encodeURIComponent(theTitle)
+ "&body="
+ encodeURIComponent("I thought you might be interested in ")
+ encodeURIComponent(theTitle)
+ encodeURIComponent(". You can view it at: \n\n\t")
+ window.location.href;

window.location.href = mail_str;
}
</script>
</head><body>
<form action="">
<button onclick="mailIt();return false;">hey</button>
</form>
</body></html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top