Accessing Layers with JavaScript : Layer : HTML : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  HTML   » [  Layer  ]   
 



Accessing Layers with JavaScript

Please note that some example is only working under IE or Firefox.


/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke 

ISBN: 067231763X
Publisher Sams CopyRight 2000

*/
<html>
<head>
  <title>JavaScript Unleashed</title>
  <style type="text/css">
  <!--
    #layer1{
    background-color: green;
    height: 100;
    left: 10;
    position: absolute;
    top: 50;
    width: 100;
    }
  -->
  </style>
  <script type="text/javascript" language="JavaScript1.2">
  <!--
    // Create global variables for browser type
    var layer = new String();
    var style = new String();
   
    // Determine if the browser is Internet Explorer, Navigator,
    // or other. Also, set the layer variable depending on the
    // type of access it needs.
    function checkBrowser(){
      if(navigator.userAgent.indexOf("MSIE"!= -1){
        layer = ".all";
        style = ".style";
      }else if(navigator.userAgent.indexOf("Nav"!= -1){
        layer = ".layers";
        style = "";
      }
    }
   
    // Take the state passed in, and change it.
    function changeState(layerRef, state){
      eval("document" + layer + "['" + layerRef + "']" + style +
                ".visibility = '" + state + "'");
    }
  //-->
  </script>
</head>

<body onload="checkBrowser()">
  <div name="layer1" id="layer1">
    DIV 1
  </div>
  <form name="form1">
    <input type="button" value="Hide"Image from book 
           onclick="changeState('layer1','hidden')">
    <input type="button" value="Show"Image from book 
           onclick="changeState('layer1','visible')">
  <form>
</body>
</html>

           
       
Related examples in the same category
1.  Layer 'srcFilter' Example
2.  Monitors divisions (or layers) on dynamic Web pages (DHTML)
3.  Hide and show layer
4.   Layer Background Colors (W3C)
5.  Setting Layer Backgrounds (W3C)
6.  The layer while rolling over the link.
7.  'layer' and 'ilayer' Tag Properties
8.  Detecting Navigator and Internet Explorer
9.   Adjusting Layer clip Properties (W3C)
10.  Comparison of Layer and Clip Location Properties (W3C)
11.   Testing Nested Layer Coordinate Systems (W3C)
12.  Nested Layer Visibility Relationships (W3C)
13.  Relationships Among zIndex Values (W3C)
14.  Dragging a Layer (W3C)
15.  Resizing a Layer (W3C)
16.  Methods and Properties of the Layer Object
17.  Layer seek
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.