JS in opera6 anders als in Opera5
spl
- javascript
Ich habe eine StickyAd-funktion von zdnet.de übernommen und leicht umgeschrieben. Geht unter ie, nn und opera5. Unter Opera 6 geht die funtkion aber nicht. Die menuleisten scollen nicht mit. Was ist der Unterschied zwischen Opera 5 und 6 ???
Da die Seite nicht offen im Netz liegt hier der Quellcode:
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Untitled</title> <SCRIPT LANGUAGE="JavaScript"> <!-- function swap(nam,num) { } //--> </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.2"> <!-- function swap(nam,num) { var bez ="menue"+num; if (! ns4) { if (nam==0){document.images[bez].src="pix/navi/strich.gif";} if (nam==1){document.images[bez].src="pix/navi/punkt.gif";} } if (ns4) { if (nam==0){document.layers["stickyad2"].document.images[bez].src="pix/navi/strich.gif";} if (nam==1){document.layers["stickyad2"].document.images[bez].src="pix/navi/punkt.gif";} } } //--> </SCRIPT> <link rel="STYLESHEET" type="text/css" href="css/lrst3.css"> </head> <body alink="#FF7F00" bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" text="#000000" topmargin="0" vlink="#FF7F00" link="#FF7F00" rightmargin="0" background="pix/lrst_bg.gif"> <script language="JavaScript1.2"> <!-- ns4 = (document.layers)? true:false ie = (document.styleSheets&&document.all)? true:false ns6 = (document.getElementById&&!document.all)? true:false; opera= (document.all&& !document.styleSheets)? true:false; top_position = 0; function move_sticky() { if (ie) document.all.stickyad.style.top=document.body.scrollTop+top_position; if (ns6||opera) document.getElementById("stickyad").style.top=pageYOffset+top_position; if (ns4) document.stickyad.top=pageYOffset+top_position; setTimeout("move_sticky()",50); }
if (! ns4) { document.write('<div id="stickyad" style="Position:absolute; left:0px;top=top_position"> <table width="100%" cellspacing="0" cellpadding="0" border="0"><tr bgcolor="#FF7F00"> <td colspan="2">gkj</td></tr><tr bgcolor="#FFFFFF"><td colspan="2" height="2"><img src="pix/navi/nopix.gif" width="2" height="2" alt="" border="0"></td></tr><tr> <td width="190"><img src="pix/navi/nopix.gif" width="190" height="1" alt="" border="0"></td> <td align="right" width="100%" bgcolor="#ffffff"><IMG SRC="pix/titel/titel.gif" hspace="0" vspace="0" ALIGN="RIGHT" WIDTH="548" HEIGHT="47" BORDER="0" ALT="Lehrstuhl für Reaktorsicherheit und -technik (Univ.-Prof. Dr.-Ing. Kurt Kugeler)"></td></tr></table> </div>'); }
if (ns4) { document.write('<layer name="stickyad" top="0" left="0"><table width="100%" cellspacing="0" cellpadding="0" border="0"><tr bgcolor="#FF7F00"><td colspan="2">gkj</td></tr><tr bgcolor="#FFFFFF"><td colspan="2" height="2"><img src="pix/navi/nopix.gif" width="2" height="2" alt="" border="0"></td></tr><tr> <td width="190"><img src="pix/navi/nopix.gif" width="190" height="1" alt="" border="0"></td> <td align="right" width="100%" bgcolor="#ffffff"><IMG SRC="pix/titel/titel.gif" hspace="8" vspace="2" ALIGN="RIGHT" WIDTH="548" HEIGHT="47" BORDER="0" ALT="Lehrstuhl für Reaktorsicherheit und -technik (Univ.-Prof. Dr.-Ing. Kurt Kugeler)"></td></tr></table> </layer>'); } move_sticky(); //--> </script> <script language="JavaScript1.2"> <!-- var menue ="'menue'"; ns4 = (document.layers)? true:false ie = (document.styleSheets&&document.all)? true:false ns6 = document.getElementById&&!document.all; opera= (document.all&& !document.styleSheets)? true:false; top_position2 = 50; function move_sticky2() { if (ie) document.all.stickyad2.style.top=document.body.scrollTop+top_position2; if (ns6||opera) document.getElementById("stickyad2").style.top=pageYOffset+top_position2; if (ns4) document.stickyad2.top=pageYOffset+top_position2; setTimeout("move_sticky2()",50); }
if (! ns4) { document.write('<div id="stickyad2" style="Position:absolute; left:0px;top=top_position2"><table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="3"><img src="pix/navi/lrst.gif" width="190" height="200" alt="" border="0"> </td></tr><tr><td><img src="pix/navi/oben.gif" width="50" height="14" alt="" border="0"></td><td></td><td></td></tr><tr> <td><img src="pix/navi/strich.gif" name="menue1" width="50" height="21" alt="" border="0"></td><td></td><td><a href="studienrichtung.php" onMouseOver="swap(1,1)" onMouseOut="swap(0,1)"><span class="navi"><font color="#000000">Studienrichtung</span></font></a></td></tr><tr><td><img src="pix/navi/strich.gif" name="menue2" width="50" height="21" alt="" border="0"></td><td></td><td><a href="forschung.php" onMouseOver="swap(1,2)" onMouseOut="swap(0,2)"><span class="navi"><font color="#000000">Forschung</span></font></a></td></tr><tr><td><img src="pix/navi/strich.gif" name="menue3" width="50" height="21" alt="" border="0"></td><td></td><td><a href="vorlesungen.php" onMouseOver="swap(1,3)" onMouseOut="swap(0,3)"><span class="navi">... gekürzt ...</div>'); }
if (ns4) { document.write('<layer name="stickyad2" top="50" left="0"><table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="3"><img src="pix/navi/lrst.gif" width="190" height="200" alt="" border="0"> </td></tr><tr><td><img src="pix/navi/oben.gif" width="50" height="14" alt="" border="0"></td><td></td><td></td></tr><tr> <td><img src="pix/navi/strich.gif" name="menue1" width="50" height="21" alt="" border="0"></td><td></td><td><a href="studienrichtung.php" onMouseOver="swap(1,1)" onMouseOut="swap(0,1)"><span class="navi"><font color="#000000">Studienrichtung</span></font></a></td></tr><tr><td><img src="pix/navi/strich.gif" name="menue2" width="50" height="21" alt="" border="0"></td><td></td><td><a href="forschung.php" onMouseOver="swap(1,2)" onMouseOut="swap(0,2)"><span class="navi"><font color="#000000">Forschung</span></font></a></td></tr><tr><td><img src="pix/navi/strich.gif" name="menue3" width="50" height="21" alt="" border="0"></td><td></td><td><a href="vorlesungen.php" onMouseOver="swap(1,3)" onMouseOut="swap(0,3)">... gekürzt ...</layer>'); } move_sticky2(); //--> </script> <noscript> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr bgcolor="#FF7F00"> <td colspan="2">gkj</td>
</tr> <tr bgcolor="#FFFFFF"> <td colspan="2" height="2"><img src="pix/navi/nopix.gif" width="2" height="2" alt="" border="0"></td> </tr> <tr> <td width="190"><img src="pix/navi/nopix.gif" width="190" height="1" alt="" border="0"></td> <td align="right" width="100%" bgcolor="#ffffff"><IMG SRC="pix/titel/titel.gif" hspace="0" vspace="0" ALIGN="RIGHT" WIDTH="548" HEIGHT="47" BORDER="0" ALT="Lehrstuhl für Reaktorsicherheit und -technik (Univ.-Prof. Dr.-Ing. Kurt Kugeler)"></td> </tr> </table> </noscript> <script language="JavaScript1.2"> document.write('<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td><img src="pix/nopix.gif" height="50" width="5"></td></tr></table>'); </script> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td width="190" valign="top"> <noscript> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td colspan="3"><img src="pix/navi/lrst.gif" width="190" height="200" alt="" border="0"> </td> </tr> <tr> <td><img src="pix/navi/oben.gif" width="50" height="14" alt="" border="0"></td> <td></td> <td></td> </tr> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="index2.php"><span class="navi"><font color="#000000">News</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="studienrichtung.php"><span class="navi"><font color="#000000">Studienrichtung</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="forschung.php"><span class="navi"><font color="#000000">Forschung</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="vorlesungen.php"><span class="navi"><font color="#000000">Lehrveranstaltungen</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="diplom.php"><span class="navi"><font color="#000000">Diplom-/Studienarbeiten</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="mitarbeiter.php"><span class="navi"><font color="#000000">Mitarbeiter</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="publikationen.php"><span class="navi"><font color="#000000">Publikationen</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="links.php"><span class="navi"><font color="#000000">Links</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="mitarbeiter.php"><span class="navi"><font color="#000000">Mitarbeiter</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="stellen.php"><span class="navi"><font color="#000000">Stellen</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="anfahrt.php"><span class="navi"><font color="#000000">Anfahrt</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="neues.php"><span class="navi"><font color="#000000">Neues</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <!-- Menupunkt --> <tr> <td><img src="pix/navi/strich.gif" width="50" height="21" alt="" border="0"></td> <td></td> <td><a href="sitemap.php"><span class="navi"><font color="#000000">Sitemap</span></font></a></td> </tr> <!-- ENDE MENUPUNKT --> <tr> <td><img src="pix/navi/unten.gif" width="50" height="59" alt="" border="0"></td> <td></td> <td></td> </tr> <tr> <td colspan="3"><img src="pix/navi/rwth.gif" width="190" height="200" alt="" border="0"></td> </tr> </table> </noscript> <script language="JavaScript1.2"> document.write('<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td><img src="pix/nopix.gif" height="1" width="190"></td></tr></table>'); </script> </td> <td valign="top">
</td> </tr> </table>
</body> </html>
Hallo,
Ich habe eine StickyAd-funktion von zdnet.de übernommen und leicht umgeschrieben. Geht unter ie, nn und opera5. Unter Opera 6 geht die funtkion aber nicht. Die menuleisten scollen nicht mit. Was ist der Unterschied zwischen Opera 5 und 6 ???
Opera kennt document.all nur, wenn der Tarnmode als IE aktiv ist. Frage besser:
if(window.opera){...}
oder
if(navigator.userAgent.indexOf("Opera")!=-1){...}
Ansonsten ist auch document.getElementById() verwendbar, sodass die Opera-Unterscheidung sogar entfallen kann. Der IE kennt diese Methode ebenfalls ab Version 5.0. Also weg mit document.all bzw. nur noch als Fallback fuer IE-Versionen < 5 einsetzen.
MfG, Thomas