...

View Full Version : Current Domain in Javascript



HelmutKopf
08-09-2004, 12:26 PM
I am working on a HTML-page, with some javascript-code, running in a local directory on my PC. Now I need the domain-name for some special operations. However, I already tried to use location.host and location.hostname, but both returned Null-Strings... Is threr any simple way to obtain this domain-information in javascript?

Thanks for help Helmut Kopf

Willy Duitt
08-09-2004, 01:12 PM
Local files do not have a domain or host name....
What exactly are you looking for? The path?

.....Willy

glenngv
08-09-2004, 01:59 PM
It should be document.domain
But it will also return an empty string on local files.

If you want the path, extract it from location.href or location.pathname

HelmutKopf
08-10-2004, 02:02 PM
Well, to insert the path hardcoded is not possible, because it is not very "user-friendly". We don't have the possibility to configure each help-file - therefore, the help-file should be able to configure the right path during load...

Thanks Helmut...

glenngv
08-10-2004, 03:13 PM
How would the local file know the domain of the help files if they are located in another server?

HelmutKopf
08-10-2004, 03:32 PM
Ok, if the help-file is running in the same domain as the server with the help files, the path is quite clear, but when the help file is running in another domain, it's necessary to use another path to the herlp library... I can implment both path expressions in the java script source of the help file, but it's necessary to knwo in which environment the help file is running to use the right path expression...

Thanks Helmut

Willy Duitt
08-10-2004, 03:47 PM
I recieved your Private Message also and quite frankly, I do not understand the problem. If the path to the file is the same on each domain the files are hosted on.... simply use relative url's and do not worry about the host....

Other than that, you need to be much clearer regarding what you are trying to do....

.....Willy

glenngv
08-10-2004, 03:48 PM
I didn't quite understand. Could you explain by using examples?

HelmutKopf
08-10-2004, 05:08 PM
Example:
There are some differentz pathes defined in javascript:
// path to the help-library in first domain
var path_domain1 = "file://archive/html"

// path to the help-library in second domain
var path_domain2 = "file://somewhere/else/html"

// will initialized during HTML-load
var helppath = ""

The Help-File with references to the help-library is running in domain 1:

// This function is called when the HTML-file is loaded
function SetHelpPath()
{
// I need the domain where I'm running....
var domain = GetDomain();
helppath = "";
// here the correct path to the help-library is set
// according to the domain:
switch (domain)
{
case Domain1:
helppath = path_domain1;
case Domain2:
helppath = path_domain2;
}
// now I cant open the correct HTML-lirary-file in
// OpenHTML(htmlname)
}

function OpenHTML()
{
with (window.location)
{
href = helppath + name;
reload();
}
}

I need the domain-name to set the correct value...

Thanks Helmut

glenngv
08-11-2004, 03:17 AM
What do you mean by domain here? Do you mean Network Domain where the machine running that code is a member of? If yes, you should look into HTAs (http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp) and WScript (http://www.devguru.com/Technologies/wscript/quickref/wshnetwork.html).

HelmutKopf
08-11-2004, 09:28 AM
Thanks a lot... With WScript.Network I cant obtain the necessary information...

Greetings Helmut

glenngv
08-12-2004, 03:43 AM
You should have made it clear at first that you meant network domain. At first, we thought you meant Web site domain, something like www.codingforums.com or in case of intranet pcname or pcname.fully.qualified.domain.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum