![]() |
SELFHTML Forumsarchiv |
|
|
Die folgende Nachricht zum Thema stammt von: Arend Knieger, 30. 06. 2003, 23:39
Hallo,
Ich habe zwei Bilder erstellt, bild1.png und bild2.png.
Wie kann ich es erreichen, dass Internet-Explorer-Benutzer und Leute ohne JavaScript bild1.png angezeigt bekommen, während Leute mit JavaScript, die aber keinen Internet Explorer verwenden bild2.png angezeigt bekommen?
Ich bin Anfänger und habe trotz Selfhtml keine Ahnung wie das gehen könnte.
Meine Lösungsskizze ist folgende:
<script ...>
if Internet-Explore document.write("<img src=\"bild1.png\" alt="" />")
else document.write("...bild2.png...");
</script>
<noscript>
<img src="bild1.png" alt="" />
</noscript>
Ist das aber wirklich elegant?
Wie mache ich die Browserabfrage?
Arend
Die folgende Nachricht zum Thema stammt von: Konrad Rudolph, 30. 06. 2003, 23:47
»» Ist das aber wirklich elegant?
naja, eleganter wäre es sicher serverseitig, aber für den Anfang reicht das sicher.
So geht's mit Browserauswahl:
\\\
<script type="text/javascript">
<!--
if(navigator.appName == "Microsoft Internet Explorer")
document.write("<img src=\"bild1.png\" alt=\"\" />")
else
document.write("<img src=\"bild2.png\" alt=\"\" />");
// -->
</script>
<noscript>
<img src="bild1.png" alt="" />
</noscript>
///
Gruß,
KonRad -
--
SELF-Code: (http://emmanuel.dammerer.at/selfcode.html)
ss:| zu:( ls:$ fo:! de:] va:| ch:? sh:) n4:# rl:? br:& js:| ie:) fl:| mo:|
Die folgende Nachricht zum Thema stammt von: jürgen j., 01. 07. 2003, 00:14
Hallo!
»» if(navigator.appName == "Microsoft Internet Explorer")
NEIN! So geht das nicht, so fängst Du evtl. auch Opera (u.a.).
Besser is das:
if(navigator.userAgent.match("MSIE") && !navigator.userAgent.match("Opera"))
Absolut sicher ist auch das nicht, mehrere Browser geben sich als IE aus.
tschüs, jürgen
Die folgende Nachricht zum Thema stammt von: Stefan Bach, 01. 07. 2003, 09:25
Hallo,
»» if(navigator.userAgent.match("MSIE") && !navigator.userAgent.match("Opera"))
Wie wäre es mit
<script type="text/javascript">
if(document.all && ! window.opera) {
document.write('<img src="bild1.png" alt="" />');
}
else {
document.write('<img src="bild2.png" alt="" />');
}
</script>
<noscript>
<img src="bild1.png" alt="" />
</noscript>
Allerdings sind die alt Attribute nicht zum Spaß da, da sollte man schon was reinschreiben.
Viele Grüße,
Stefan
--
Lass dir das Tanzen NICHT verbieten
http://tanzverbot.de
Die folgende Nachricht zum Thema stammt von: Ingo, 01. 07. 2003, 00:38
hi Arend,
wenn das Bild für den IE nicht transparent und nicht kleiner als das Alternativbild ist und es außerdem absolut positioniert werden darf, dann gibt's noch eine Methode ganz ohne Javascript:
<img src="bild1.png" alt="" style="position:absolute; top:0; left:0;">
<!--[if IE]><img src="bild2.png" alt="" style="position:absolute; top:0; left:0;"><![endif]-->
Hiermit bekommt allerdings nur der Windows-IE das bild1.png zu sehen (dafür allerdings auch keine Browser, die sich als IE ausgeben).
gruß
Ingo
Die folgende Nachricht zum Thema stammt von: Guillermo, 01. 07. 2003, 09:11
»» <!--[if IE]>...<![endif]-->
Gibt es noch mehr derlei Syntax? Das klingt ja ziemlich interessant.
Guillermo
Die folgende Nachricht zum Thema stammt von: wahsaga, 01. 07. 2003, 10:48
hi,
»» »» <!--[if IE]>...<![endif]-->
»»
»» Gibt es noch mehr derlei Syntax? Das klingt ja ziemlich interessant.
das sind die sog. "conditional comments" des ie (->google).
gruss,
wahsaga
© 1998-2006
Impressum, Software: Classic Forum