Hallo,
ich versuche herauszufinden, warum ich im IE nicht auf Attribute von dynamisch erzeugten IFrames zugreifen kann. Im Firefox und im Opera klappt das problemlos. Die IFrames werden auch im IE erzeugt (die Schleife in der Funktion 'check' läuft entsprechend oft), nur der Zugriff darauf will partout nicht klappen.
Code-Schnipsel zur Demonstration des Problems:
<html>
<head>
<title>Zugriff auf Inhalt dynamisch erzeugter IFrames</title>
<script>
function addIFrames () {
var ifr = document.createElement ( "iframe" );
ifr.style.width = 0;
ifr.style.height = 0;
ifr.style.visibility = "hidden";
ifr.name = "bla";
ifr.src = "irgendwas.html"; // irgendeine HTML-Seite
document.body.appendChild ( ifr );
var ifr = document.createElement ( "iframe" );
ifr.style.width = 0;
ifr.style.height = 0;
ifr.style.visibility = "hidden";
ifr.name = "blub";
ifr.src = "nochirgendwas.html"; // noch eine HTML-Seite
document.body.appendChild ( ifr );
}
function check () {
var ifrname = "bla";
for ( var it = 0 ; it < top.frames.length ; it ++ ) {
// Attribut 'name' ist im IE leer:
document.body.innerHTML += "<br/>frame name: " + top.frames[it].name;
}
// wirft einen Fehler im IE ("top.frames.bla.document ist Null oder kein Objekt"):
document.body.innerHTML += "<br/>" + top.frames["bla"].document.body.innerHTML;
}
</script>
<style type="text/css">
</style>
</head>
<body onload="addIFrames()">
<a href="javascript:check()">check</a>
</body>
</html>