Laden habe ich eine Seite index.htmlWarum Alarm-Funktion funktioniert nicht, wenn sie mit Ajax
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Lufia</title>
<script language="javascript" type="text/javascript">
function ajax()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById('mydiv').innerHTML=xmlhttp.responseText;
}
xmlhttp.open("GET",'welcome.html',true);
xmlhttp.send();
}
</script></head>
<body>
<button onclick="ajax();"></button><div id="mydiv"></div></body>
</html>
Und eine andere Seite genannt welcome.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Lufia</title>
<body onload="alert('ank');">welcome
</body>
</html>
ich es will ank alarmieren, wenn welcome.html wird über Ajax geladen, da die Alert-Funktion auf das Attribut body onload von welcome.html geschrieben wird