SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    130
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Most reliable way to fetch domain name?

    Hi, I have tried location.hostname but this does not work.

    I have also tried
    var tmp is new Location();
    alert(tmp.hostname);
    witch does not work eighter.

    How do i do this?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you only need to use location.hostname

    copy and paste this into the address bar:

    javascript:alert(location.hostname);


  3. #3
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    130
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yeah, That works fine.

    It must be the context that i'm using it in that is causing problems.

    I call this file with css
    img {behavior:url(http://<?php echo $_SERVER['HTTP_HOST'];?>/includes/colorpicker/pngbehavior.htc);}

    The file pngbehavior.htc has this code in it
    Code:
    <public:component>
    <public:attach event="onpropertychange" onevent="propertyChanged()" />
    <script>
    
    var supported = /MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32";
    var realSrc;
    //the path
    var blankSrc = "http://" + location.hostname + "/includes/colorpicker/blank.gif";
    
    if (supported) fixImage();
    
    function propertyChanged() {
       if (!supported) return;
    
       var pName = event.propertyName;
       if (pName != "src") return;
       // if not set to blank
       if ( ! new RegExp(blankSrc).test(src))
          fixImage();
    };
    
    ....
    
    </script>
    </public:component>

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    130
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Nevermind it does work. I probably had something wrong in my setup.


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
  •