I am trying to check whether an iframe has loaded after the user clicks a button.
I have
$('#MainPopupIframe').load(function(){
console.log('load the iframe')
//the console won't show anything even if the iframe is loaded.
})
HTML
<button id='click'>click me</button>
//the iframe is created after the user clicks the button.
<iframe id='MainPopupIframe' src='http://...' />...</iframe>
Any suggestions?
By the way, my iframe is created dynamically. It doesn’t load with the initial page load.
I imagine this like that:
You may try this (using
jQuery
)jsfiddle DEMO.
Update: Using plain
javascript
jsfiddle DEMO.
Update: Also you can try this (dynamic iframe)
jsfiddle DEMO.
You can try onload event as well;