SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    append current url to existing link with javascript

    Hi I have this link

    Code:
    http://www.facebook.com/sharer.php?u=
    I want to append the current url to it and make thw whole thing a link. I've got the below code which is almost working I'm just not sure of how to append the link to the window.location part. ANy help would be great. Thanks

    BELOW CODE NOT WORKING

    Code:
     document.getElementById("facebook").href = "http://www.facebook.com/sharer.php?u=".window.location.toString();

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Something like this?

    Code:
    <a href="http://www.facebook.com/sharer.php?u=" id="facebook">FaceBook Link</a>
    
    var link = document.getElementById("facebook"),
        currUrl = document.URL;
    
    link.href = link.href + currUrl;

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks this is working. Cheers

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    No probs
    Thanks for taking the time to report back.


Bookmarks

Posting Permissions

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