home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / dhtmlunl / dhtml.exe / CD Content / Chap15 / dun15_5.txt < prev    next >
Encoding:
Text File  |  1997-12-18  |  1.8 KB  |  55 lines

  1. <IMG NAME=arrow SRC="arrow.gif" ALIGN=left>
  2.  
  3.  
  4.  
  5. <DIV ID=banner STYLE="position: absolute; left: 72; top: 15;">
  6.  
  7.   <FONT FACE="Arial, Helvetica" SIZE=+2>
  8.  
  9.       Exposing Page Elements Cross-Browser
  10.  
  11.   </FONT>
  12.  
  13. </DIV>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. <SCRIPT>
  20.  
  21.   // Detect if browser is IE4 and if so, assign objectRoot to contain
  22.  
  23.   // 'document.all' instead of 'document'
  24.  
  25.   //
  26.  
  27.   objectRoot = "document";
  28.  
  29.   if (navigator.appName.indexOf("Internet Explorer") != -1 &&
  30.  
  31.       navigator.appVersion.charAt(0) == '4')
  32.  
  33.         objectRoot = "document.all";
  34.  
  35. </SCRIPT>
  36.  
  37.  
  38.  
  39.  
  40.  
  41. <BR><BR>
  42.  
  43. <P>The <TT>DIV</TT> element is normally reflected as
  44.  
  45. <TT>document.banner</TT> in Communicator 4.0 and
  46.  
  47. <TT>document.all.banner</TT> in IE4.  By assigning
  48.  
  49. <TT>objectRoot</TT> to contain the differences in the object hierarchy,
  50.  
  51. the <TT>eval()</TT> function can be used to dynamically access the
  52.  
  53. <TT>DIV</TT> element using the correct notation for each browser.</P>
  54.  
  55.  
  56.  
  57. <P>The attributes of the <TT>DIV</TT> element that are reflected in both
  58.  
  59. browsers include:</P>
  60.  
  61.  
  62.  
  63. <BLOCKQUOTE>
  64.  
  65. <SCRIPT>
  66.  
  67.   document.writeln("<B>id:</B> " + eval(objectRoot + ".banner.id"));
  68.  
  69.   document.writeln("<BR>");
  70.  
  71. </SCRIPT>
  72.  
  73. </BLOCKQUOTE>
  74.  
  75.  
  76.  
  77. <P>The <TT>IMG</TT> element is dynamically accessed as
  78.  
  79. <TT>document.arrow</TT> in Communicator 4.0 and
  80.  
  81. <TT>document.all.arrow</TT> in IE4 using the <TT>objectRoot</TT>
  82.  
  83. variable and the <TT>eval()</TT> function.  </P>
  84.  
  85.  
  86.  
  87. <P>The attributes of the <TT>IMG</TT> element that are reflected in both
  88.  
  89. browsers include:</P>
  90.  
  91.  
  92.  
  93. <BLOCKQUOTE>
  94.  
  95. <SCRIPT>
  96.  
  97.    document.writeln("<B>name:</B> " + eval(objectRoot + ".arrow.name"));
  98.  
  99.    document.writeln("<BR>");
  100.  
  101.    document.writeln("<B>src:</B> " + eval(objectRoot + ".arrow.src"));
  102.  
  103.    document.writeln("<BR>");
  104.  
  105. </SCRIPT>
  106.  
  107. </BLOCKQUOTE>
  108.  
  109.