SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast darkhorse162's Avatar
    Join Date
    Oct 2006
    Location
    Duluth, MN
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    layers not working in Safari, work fine in IE and FF

    Here is my JS code in the head section of my page:

    Code:
    <script type="text/javascript">
    	function ShowLayer(id, action){
    		eval("document.getElementById('" + id + "').style.visibility='" + action + "'");
    		document.location = "#" + id;
    	}
    </script>
    Now here is an example of a div that I have in the body.

    Code:
    <div id="heading1" style="visibility: hidden;position: static;">
    	<h1>
    		<a name="heading1">A HEADING HERE</a>
    	</h1>
    	 <p>
    	 	Some text here
    	</p>
    </div>
    There is a number of these divs all nested inside a div. The idea is each time they click on a link:

    Code:
    <a href="javascript:ShowLayer('heading1','visible')">A HEADING</a>
    The correct nested div will be displayed within the div and it will jump down to show it by using the 'document.location'.

    Now this works just fine in IE and FF, but with Safari, it will display the very first div at the top once clicked, but then it acts like it's still loading and none of the other links will work when they are clicked on.

    Any help?
    .:::darkhorse162:::.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why it fails in Safari, but there is no need for an eval in your function. The same can be achieved without it
    Code:
    document.getElementById(id).style.visibility = action;

  3. #3
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps Safari would like 'window.location.href'. Document.location is deprecated.

  4. #4
    SitePoint Enthusiast darkhorse162's Avatar
    Join Date
    Oct 2006
    Location
    Duluth, MN
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm...I tried both of those suggestions together and it still is not working...thanks for the ideas though...any others?
    .:::darkhorse162:::.

  5. #5
    SitePoint Enthusiast darkhorse162's Avatar
    Join Date
    Oct 2006
    Location
    Duluth, MN
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure Safari is getting hung up on the
    Code:
    document.location = "#" + id;
    or
    Code:
    window.location.href = "#" + id;
    Is there a better way of doing this? It doesn't ever seem to finish loading the page once you click on one of the links as if it were stuck here in a loop or just can't get past it.

    edit:
    I've also tried
    Code:
    document.location.href = "#" + id;
    .:::darkhorse162:::.


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
  •