window.location.href

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brvsra

    window.location.href

    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="javas cript">
    function mailpage()
    {
    mail_str = "mailto:?subjec t=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>


  • sancha

    #2
    Re: window.location .href

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

    var mail_str = "mailto:?subjec t="+encodeURICo mponent("Check out the ")
    + encodeURICompon ent(document.ti tle);
    mail_str += "&body="+encode URIComponent("I thought you might be
    interested in the ") +
    encodeURICompon ent(document.ti tle);
    mail_str += encodeURICompon ent(". You can view it at, ") +
    window.location .href;

    i used the encodeURICompon ent as encode decode has been deprecated in
    javascript. Hope it helps

    Comment

    • Fred Oz

      #3
      Re: window.location .href

      sancha wrote:[color=blue]
      > Hi i am not that good in javascript but i faced a similar problem.
      > Maybe this will help.[/color]

      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:?subjec t="
      + encodeURICompon ent("Check out ")
      + encodeURICompon ent(theTitle)
      + "&body="
      + encodeURICompon ent("I thought you might be interested in ")
      + encodeURICompon ent(theTitle)
      + encodeURICompon ent(". 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>

      Comment

      Working...