www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: window.location in link ???

  1. #1
    Join Date
    Jan 2006
    Posts
    301

    window.location in link ???

    Is it possible to grab the full url into my "email a friend" script along with the body text?


    <INPUT TYPE="image" src="fun2.gif" border=0 value="grab" name="grab" alt="Email a Friend This Page!" onClick="parent.location='mailto:friends@email-here.com?subject=Check out this Website&body=Hello, I found a great web page at window.location'">
    www.unitingbands.com - Where Talents Unite!

  2. #2
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    Why not just do this
    Code:
    <a href="mailto:friends@email-here.com?subject=Check out this Website&body=Hello, I found a great web page at window.location.href">
    <img src"fun2.gif" border=0 value="grab" name="grab" alt="Email a Friend This Page!" />
    </a>

  3. #3
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,403
    tested and works:

    Code:
    <a href="javascript:window.location='mailto:friends@email-here.com?subject=Check out this Website&body=Hello, I found a great web page at ' + window.location.href">
    <img src"fun2.gif" border=0 value="grab" name="grab" alt="Email a Friend This Page!" />
    </a>

  4. #4
    Join Date
    Jan 2006
    Posts
    301
    thanks but I tried that one already. It just shows in the email body:

    "Hello, I found a great web page at window.location.href"
    www.unitingbands.com - Where Talents Unite!

  5. #5
    Join Date
    Jan 2006
    Posts
    301
    Thanks Aaron and the email body does work BUT it changes my initial web page to something else being a blank page with the url in it.

    we are close, any ideas?
    www.unitingbands.com - Where Talents Unite!

  6. #6
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,403
    Code:
    <a href="#" onclick="window.location='mailto:friends@email-here.com?subject=Check out this Website&body=Hello, I found a great web page at ' + window.location.href">
    <img src"fun2.gif" border=0 value="grab" name="grab" alt="Email a Friend This Page!" />
    </a>

  7. #7
    Join Date
    Jan 2006
    Posts
    301
    thanks aaron, that was it! Thanks!
    www.unitingbands.com - Where Talents Unite!

  8. #8
    Join Date
    Jan 2006
    Posts
    301
    One more thing I just ran into...

    When the URL has an "&" in it everything after this is being stripped off. Any idea on retaining the rest of the url in these cases? I guess it could be a limitation of the browser...
    www.unitingbands.com - Where Talents Unite!

  9. #9
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,403
    sorry, dont know the answer to that one

  10. #10
    Join Date
    Jan 2006
    Posts
    301
    Thanks for trying! Any one else know if this is possible?
    www.unitingbands.com - Where Talents Unite!

  11. #11
    Join Date
    Sep 2006
    Location
    Copenhagen, Denmark
    Posts
    1,253
    HTML Code:
    <a href="#" onclick="window.location='mailto:friends@email-here.com?subject=Check out this Website&body=Hello, I found a great web page at ' + window.location.href + window.location.search">
    <img src"fun2.gif" border=0 value="grab" name="grab" alt="Email a Friend This Page!" />
    </a>
    #define question (2B || !2B)
    HTMLElement and W3C Event Handling in IE
    My JavaScript Library

    Don't PM me about answers to questions. If I don't reply in a thread it's because:
    • You didn't read the message posting guidelines
    • Your code is too unstructured and/or formatted poorly - correcting it is too time consuming
    • I simply don't know the answer

  12. #12
    Join Date
    Jan 2006
    Posts
    301
    Nice thought but this rendered the same output, it's still stripping everything from the &.
    www.unitingbands.com - Where Talents Unite!

  13. #13
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    You need to encode the text using URL safe characters:

    Code:
    function emailPage() {
      var messageText = 'Hello, I found a great web page at ' + window.location;
      var subjectText = 'Check out this Website';
      var email = prompt("Enter your friend's email address:", 'email@address.com');
      
      window.location = 'mailto:' + email + 
          '?subject=' + encodeURIComponent(subjectText) +
          '&body=' + encodeURIComponent(messageText);
    }
    Then to use this function:
    HTML Code:
    <a href="#" onclick="emailPage(); return false;">Email This Page!</a>
    Last edited by toicontien; 07-20-2007 at 05:19 PM.

  14. #14
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    The query string is not considered part of the URL. You can retrieve these vales through the window.location.search property.

  15. #15
    Join Date
    Jan 2006
    Posts
    301
    Hey toicontien this works great however I don't want the prompt for an email address. Is it possible to take that part out of the code?
    www.unitingbands.com - Where Talents Unite!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles