window.location.href

Discussion in 'Javascript' started by Brvsra, Jan 11, 2005.

  1. Brvsra

    Brvsra Guest

    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>
    Brvsra, Jan 11, 2005
    #1
    1. Advertising

  2. Brvsra

    sancha Guest

    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
    sancha, Jan 11, 2005
    #2
    1. Advertising

  3. Brvsra

    Fred Oz Guest

    sancha wrote:
    > 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>
    Fred Oz, Jan 11, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    1
    Views:
    10,174
    Boban Dragojlovic
    Jun 24, 2003
  2. Joshua Beall
    Replies:
    26
    Views:
    219,904
    AndreiKaa
    Jun 29, 2007
  3. saiho.yuen
    Replies:
    3
    Views:
    406
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    441
  5. Alex Bird
    Replies:
    3
    Views:
    167
    Thomas 'PointedEars' Lahn
    May 9, 2008
Loading...

Share This Page