Advanced Search

Results 1 to 4 of 4

Thread: Automatically show a default layer

  1. #1
    Join Date
    Feb 2010
    Posts
    66
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Exclamation Automatically show a default layer

    Hi Guys,

    Was just wondering if you could help me out here!

    If you refer to the Javascript code below, how can I set it so it shows a default Div layer upon page load?

    Code:
    <script type="text/javascript">
    	window.onload = function(){
    		if(location.href.indexOf('layer=') != -1)
    			if(document.getElementById(location.href.split('layer=')[1]))
    				document.getElementById(location.href.split('layer=')[1]).style.display = 'block';
    	}
    </script>
    Right, that's the Javascript and below is the Div layer it would select, for example I'm using the first layer of five:

    Code:
    <div id="one" style="display:none;">
    </div>
    On page load, all Div layers are hidden as they feature the display:none style, seen in the above example. Is there a way of selecting a default Div so it doesn't just show a blank page?

    This is the page:

    http://www.british-certification.com...tification.htm

    By the way, I don't want to just link straight to the layer like this:

    http://www.british-certification.com....htm?layer=one

    Thanks!

    Mark

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,702
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    Code:
    <script type="text/javascript">
    	window.onload = function(){
    		if(location.href.indexOf('layer=') != -1){
    			if(document.getElementById(location.href.split('layer=')[1])){
    				document.getElementById(location.href.split('layer=')[1]).style.display = 'block';
    				return;
    			}
    		}
    		document.getElementById('one').style.display = 'block';
    	}
    </script>
    However, if javascript is disabled or unavailable, nothing will be shown. For that, the easiest thing would be to include a:

    HTML Code:
    <noscript>This Page Requires Javascript</noscript>
    In some portion of the page that can be seen. You may, should in fact, replace the text "This Page Requires Javascript" with something more informative, perhaps all of the information from all of the divisions, or a link to an alternate page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2010
    Posts
    66
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Hey there,

    I've just tested it out and that doesn't seem to be working. It doesn't show any layers at all when you click on the menu.

    Mark

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,702
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    You didn't copy my code as it is in my post, you left out at least one curly brace. Go back and copy it exactly and paste it over yours.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •