SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.location.hash not working in safari, chrome & mozilla.

    I have a jscript that I added a line of code to to allow me to have a clever way of showing hidden divs further down the page.

    This is my script and it seems to work in I.E, but not in the others, so was wondering if anybody could help me with this.

    Code:
    <script language="javascript" type="text/javascript">
    function showonlyonev2(thechosenone) {
          var newboxes = document.getElementsByTagName("div");
          for(var x=0; x<newboxes.length; x++) {
                name = newboxes[x].getAttribute("name");
                if (name == 'newboxes-2') {
                      if (newboxes[x].id == thechosenone) {
                            if (newboxes[x].style.display == 'block') {
                                  newboxes[x].style.display = 'none';
                            }
                            else {
                                  newboxes[x].style.display = 'block';
                            }
                      }else {
                            newboxes[x].style.display = 'none';
                      }
                }
          }
    	  window.location.hash = "#info";
    } 
    </script>
    And this is the other bit.

    HTML Code:
    <a name="Info" id="Info2"></a>
    If it helps this is the page.

    http://www.crownatcaldicotcastle.co.uk/

    It supposed to work when you click one of the titles in the 4 categories across the middle of the page. eg Medieval Banquets, Weddings etc

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by multichild View Post
    This is my script and it seems to work in I.E, but not in the others, so was wondering if anybody could help me with this.
    It seems to be setting the hash for me in Chrome and Firefox.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, do you mean that yes the hash is being set in the url, but is the page moving to see the then open hidden div at the bottom of the screen.

    Or am I mad, and it all works OK for you.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by multichild View Post
    Hi, do you mean that yes the hash is being set in the url, but is the page moving to see the then open hidden div at the bottom of the screen.

    Or am I mad, and it all works OK for you.
    Ahh, you're wanting other side-effects to occur. It sets the hash in the url.

    If you want the page to scroll to the element identified as "Info", you will need to set the hash to that instead. Pay attention to the capitalisation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OMG! I dont believe that, I didnt make both capitals....

    I'm sorry to waste your time guys.

  6. #6
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now presumably you'll turn your attention to creating a fallback, so that those 'links' aren't inexplicably broken if JS is disabled or unavailable.
    Tab-indentation is a crime against humanity.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    Now presumably you'll turn your attention to creating a fallback, so that those 'links' aren't inexplicably broken if JS is disabled or unavailable.
    A good way to do that is to have the link href go to "#Info" so that the script isn't solely responsible for setting that hash.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right yes I didnt think of that, will do that thank you.


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
  •