Ich habe einen iFrame, an den ich nach dem Laden von ..__ einen JavaScript-Befehl senden möchte. Mein aktueller Code sieht folgendermaßen aus:
<iframe src="http://www.test.tld/" onload="__doPostBack('ctl00$ctl00$bLogout','')">
Mit diesem Code wird der Befehl jedoch nicht ausgeführt. Was muss ich ändern, damit es funktioniert? Nur Chrome und Firefox müssen unterstützt werden.
Verwenden Sie die .onload
-Funktion von iFrame für JavaScript:
<iframe id="my_iframe" src="http://www.test.tld/">
<script type="text/javascript">
document.getElementById('my_iframe').onload = function() {
__doPostBack('ctl00$ctl00$bLogout','');
}
</script>
document.querySelector("iframe").addEventListener("load", function() {
this.style.backgroundColor = "red";
alert(this.nodeName);
});
<iframe src="http://www.example.com/" ></iframe>
Ihr Code ist korrekt. Testen Sie einfach, um sicherzustellen, dass es aufgerufen wird.
<script>
function doIt(){
alert("here i am!");
__doPostBack('ctl00$ctl00$bLogout','')
}
</script>
<iframe onload="doIt()"></iframe>
Die Antwort von Jasper war fast richtig. Es fehlte nur httpSfür die src des iframe.
HTML:
<iframe src="https://www.example.com/" ></iframe>
JavaScript:
document.querySelector("iframe").addEventListener("load", function() {
this.style.backgroundColor = "red";
alert(this.nodeName);
});