chef1568
Goto Top

Javascript oder HTML nach DOM laden

Hallo,

ich habe ein Problem mit dem Seitenaufbau meiner Webseite.
Ich möchte 2 Inhalte erst nach Aufbau des DOM´s laden:

1. Javascript:
<head>
........
        <script type="text/javascript">  
	       window.onload = function (){
	             //<![CDATA[
			  var tl_loc0=(window.location.protocol == "https:")? "https://ssl.example.net/javascript/logo.js" :  
     			  "http://ssl.example.net/javascript/logo.js  
		            document.writeln('<scr' + 'ipt language="JavaScript" src="'+tl_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>');  
                     //]]>
		  };
         </script>
.......
</head>
--> Ergebnis: Die Seite baut sich erst bis DOM auf und geht danach aber sofort in eine Endlosschleife (weiße Seite)


1. HTML:
<body>
        <script type="text/javascript">  
	        window.onload = function (){
		        document.getElementById("watch");  
        	};
        </script>

        <p id="watch" align="center"><a href="http://www.example.de"><img alt="" src="https://example.html" /></a></p>  
</body>
--> Ergebnis: der HTML-Part wird geladen als wäre kein JS vorhanden

Hat jemand eine Idee, wieso beide Aktionen nicht funktionieren?

mfg

Content-Key: 228839

Url: https://administrator.de/contentid/228839

Printed on: April 20, 2024 at 02:04 o'clock

Member: colinardo
colinardo Feb 06, 2014, updated at Feb 11, 2014 at 09:49:03 (UTC)
Goto Top
Hi,
da war ein Flüchtigkeitsfehler im JavaScript-Teil, es fehlte ein Anführungszeichen und ein abschließendes Semikolon am Ende der Zeile 6 bzw. 7 deines JavaScripts
<script type="text/javascript">  
   window.onload = function (){
		 //<![CDATA[
	var tl_loc0=(window.location.protocol == "https:") ? "https://ssl.example.net/javascript/logo.js" : "http://ssl.example.net/javascript/logo.js";  
	document.write('<script language="JavaScript" src="' + tl_loc0 +' " type="text\/javascript">' + '<\/script>');  
			 //]]>
  };
</script>
und was soll das allein stehende
document.getElementById("watch"); 
bewirken ?? Hier wird ja keinerlei Variable zugewiesen ...

Grüße Uwe