How can I display the Current URL

Discussion in 'JavaScript' started by ivenms, Aug 30, 2007.

  1. #1
    I really need to display the current URL on the page with JavaScript.

    How can I do it?

    What is the procedure to get the URL of the page with the help of JavaScript?

    Thanks in advance.
     
    ivenms, Aug 30, 2007 IP
  2. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Still waiting......

    I am really surprised of not seeing any reply on this forum.

    I really need help on this time. Hope to find the answer sooner.

    Thanks in advance.
     
    ivenms, Aug 31, 2007 IP
  3. garazy

    garazy Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    alert ( document.location.href );


    Try that.
     
    garazy, Aug 31, 2007 IP
  4. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't want alert part.

    I need to output ( display ) the page URL dynamically to the user on the page.

    Not on the way of alert message.
     
    ivenms, Aug 31, 2007 IP
  5. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #5
    http://uk3.php.net/reserved.variables

    echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    PHP:
    That should work.

    EDIT: Sorry, didn't realise this was the JavaScript forum.

    I don't know any javascript at all, but isn't JS a clientside language thus making it impossible?
     
    crazyryan, Aug 31, 2007 IP
  6. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I know PHP on great extent.

    But improving my JavaScript.

    Iam looking for JavaScript code to give the result.

    Also looking for some other techniques with JavaScript. I believes that JavaScript having a great role for my dynamic pages.

    For my page's completion, I need answers like this question. If some one there who are expert on JavaScript, solve my question. I will definitely contact him/her with some other questions.
     
    ivenms, Aug 31, 2007 IP
  7. tcmeyers

    tcmeyers Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I'm totally new to JavaScript, but this seems to work.... put this code in your HTML right where the URL is supposed to appear:

    <script type="text/javascript">
    <!--
    document.write(document.location.href);
    //-->
    </script>


    -Troy
     
    tcmeyers, Aug 31, 2007 IP
  8. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    That works for me now...

    Thanks... But now, it is time to ask another question:

    How I can display the page's title Dynamically?

    Hope that the answer will get quickly...
     
    ivenms, Aug 31, 2007 IP