Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Current Domain in Javascript

    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

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local files do not have a domain or host name....
    What exactly are you looking for? The path?

    .....Willy

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    How would the local file know the domain of the help files if they are located in another server?

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I didn't quite understand. Could you explain by using examples?

  • #9
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Domain...

    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

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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 and WScript.

  • #11
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot... With WScript.Network I cant obtain the necessary information...

    Greetings Helmut

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •