PDA

View Full Version : Automatically show a default layer



lowmarklow
05-13-2010, 10:12 AM
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?



<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:



<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/iso-9001-certification.htm

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

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

Thanks!

Mark

jscheuer1
05-13-2010, 05:02 PM
<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:


<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.

lowmarklow
05-14-2010, 11:00 AM
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

jscheuer1
05-14-2010, 02:33 PM
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.