Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-05-2009
Member
 
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?
Reply With Quote
  #2  
Old 15-05-2009
Member
 
Join Date: May 2008
Posts: 2,383
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>
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 15-05-2009
Member
 
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.
Reply With Quote
  #4  
Old 15-05-2009
Member
 
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>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to get the hostname using JavaScript"
Thread Thread Starter Forum Replies Last Post
How to hide hostname from router mathis Networking & Security 3 30-08-2013 11:49 AM
Unable to resolve hostname via ssh Hipolit Networking & Security 2 10-09-2011 10:37 PM
How can i change the hostname on Solaris Xylina Networking & Security 3 18-08-2009 10:05 PM
Can ping IP but not hostname supernoob Networking & Security 3 29-07-2009 09:45 PM


All times are GMT +5.5. The time now is 09:08 PM.