Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iFrame onload JavaScript event

I have an iFrame, where I want to send a JavaScript command after loading. My current code looks like this:

<iframe src="http://www.test.tld/" onload="__doPostBack('ctl00$ctl00$bLogout','')"> 

But with this code the command isn't executed. What must I change to make it work? Only Chrome and Firefox have to be supported.

like image 681
Peleke Avatar asked Mar 24 '15 13:03

Peleke


2 Answers

Use the iFrame's .onload function of 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>     <!--OTHER STUFF--> </iframe> 
like image 149
Jasper Avatar answered Sep 28 '22 00:09

Jasper


document.querySelector("iframe").addEventListener( "load", function(e) {        this.style.backgroundColor = "red";      alert(this.nodeName);        console.log(e.target);    } );
<iframe src="example.com" ></iframe>
like image 42
antelove Avatar answered Sep 27 '22 23:09

antelove