Results 1 to 4 of 4

Thread: How to get the hostname using JavaScript

  1. #1
    Join Date
    Jan 2009
    Posts
    638

    How to get the hostname using JavaScript

    I want the hostname of my website using JavaScript. Do you know how to get hostname? Which parameter or function retrieves the hostname?

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to get the hostname using JavaScript

    Try using nametop.location.host, something like this:

    HTML Code:
    <script language = "JavaScript">
    function name ()
    {
    alert (nametop.location.host);
    }
    </script>

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: How to get the hostname using JavaScript

    To get host name in JavaScript add
    Code:
    var hostname = window.location.hostname
    this statement in your code.

    However if you want you can use "VIH_HostName" variable. The client host name is stored in this variable.

  4. #4
    Join Date
    May 2008
    Posts
    945

    Re: How to get the hostname using JavaScript

    Here is a simple example how to get the hostname of your web site. Basically the hostname property of Location class represents the hostname portion of the URL.

    HTML Code:
    <html>
        <head>
        <title> Using the hostname property of the Location object</title>
        </head>
        <body>
        <script language="JavaScript">
        <!--
        function show(){
             alert(document.location.hostname);
        }
        -->
        </script>
        <form name="form1">
        Click the button to get the current location.hostname
        <br>
        http://www.java2s.com
        <br>
        <input type="button" name="gethost" value="Get hostname" onClick='show()'>
        <br>
        </form>
        </body>
        </html>

Similar Threads

  1. How to hide hostname from router
    By mathis in forum Networking & Security
    Replies: 3
    Last Post: 30-08-2013, 11:49 AM
  2. Unable to resolve hostname via ssh
    By Hipolit in forum Networking & Security
    Replies: 2
    Last Post: 10-09-2011, 10:37 PM
  3. How can i change the hostname on Solaris
    By Xylina in forum Networking & Security
    Replies: 3
    Last Post: 18-08-2009, 10:05 PM
  4. Can ping IP but not hostname
    By supernoob in forum Networking & Security
    Replies: 3
    Last Post: 29-07-2009, 09:45 PM

Tags for this Thread

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
  •  
Page generated in 1,713,503,307.15146 seconds with 17 queries