Click to See Complete Forum and Search --> : how to get host name in JavaScript?


jorx
05-09-2003, 11:15 AM
I need to get the host name in the plain html page, this is because we have a browser based application and we want to disply it on the active desktop of our client station, and because, the active desktop, only supports html archives, I can't put a URL in the active desktop wallpaper, it must be a html file, saved on the local hard disk or a netword drive.

So, the servers are always changing, and I need to get the host name (domain controler) so that, the html can send a redirect to the archive in the correct host. I now that if I use some server tech (php, asp, jsp, etc) it is just a line of code, using the SERVER_VARIABLES, but in javascript, client sided, I don't know if I can do this.:rolleyes:

pyro
05-09-2003, 11:21 AM
Try using top.location.host to return the host name (www.yourdomain.com)

jorx
05-09-2003, 11:39 AM
thanks for the:
<script language="JavaScript">
function name(){
alert(nametop.location.host);
}
</script>

but this only works went I call the page from a web client, and went I call it from a logical drive o network drive, it does not display anything, and I just need to display to server name, like in asp, I can do var server = Response.ServerVariables("HOST_NAME"); and it returns http://[serverName] and I just need that server name... thanks.:confused:

pyro
05-09-2003, 11:48 AM
I don't think you can do that. All you can return from the location object on a local disk is the href, the protocol, the pathname, the search, and the hash. Try saving http://www.infinitypages.com/research/location.htm to you local disk and see the values you can return.

pyro
05-09-2003, 11:50 AM
Wait.... Do you have a local server running? (ie localhost) If so, it should work fine. The link I pointed you to above works fine on my testing server...

jorx
05-09-2003, 12:08 PM
thanks for that, and well, I guess that we must config that address each time the server changes, its only one archive, not a big deal, thanks for the location.htm page, will work for some other things in this app.