how do I use javascript to get url of current page

Discussion in 'JavaScript' started by sleepy, Mar 13, 2007.

  1. #1
    Hi guys maybe someone can help me,
    I useing this code to add a digg submit news button to a html web site I'm working on and the news item relates to what on each individual page,

    <script type="text/javascript">
    digg_url = 'http://www.webaddressexample.co.uk';
    digg_bgcolor = '#ffffff';
    digg_skin = 'compact';

    </script>
    <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
    </p>

    Trouble is I need this on over 200 pages and dont want to type in the address of each indvidual page, is there a way I can use javascript to find or get the url of the page?

    cheers for any help
     
    sleepy, Mar 13, 2007 IP
  2. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #2
    "window.location" has what's in the address bar of your browser ...
     
    kajakske, Mar 13, 2007 IP
  3. sleepy

    sleepy Guest

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks , will give that a try
     
    sleepy, Mar 13, 2007 IP
  4. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If that doesn't work, also window.location.href might have the right URL :)
     
    DeViAnThans3, Mar 13, 2007 IP
  5. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #5
    DeViAnThans3 is correct, you may if you wish use, document.location.href
     
    datropics, Mar 13, 2007 IP
  6. sleepy

    sleepy Guest

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for the help guys:)
     
    sleepy, Mar 20, 2007 IP
  7. hitswa

    hitswa Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i m also trying same thing but m doing for facebook comment pledge...

    my code is

    div id="fb-root"></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=135249243225862";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <div class="fb-comments" data-href="javascript:document.location.href;" data-num-posts="2" data-width="500"></div>
    </body>


    i have used javascript as told by you guys which is here in BOLD in this script...

    anybody tell me how this work how can i use javascript to get current page URL...

    Regards
    Hitswa
     
    hitswa, Dec 27, 2011 IP
  8. hitswa

    hitswa Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yes let me include the output of above mentioned code

    its like this

    Warning: http: //invalid.invalid/ is unreachable.
     
    hitswa, Dec 27, 2011 IP
  9. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #9
    Please do not hijack threads. You will get more and better answers by STARTING YOUR OWN THREAD!!!
     
    mmerlinn, Dec 31, 2011 IP