Jump to content

Execute Javascript After Iframe Has Loaded..?


Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"   "http://www.w3.org/TR/html4/strict.dtd"><html>	<head>		<meta http-equiv="content-type" content="text/html;charset=UTF-8">		<title></title>		<script type="text/javascript">			function init () {				document.getElementById("myframe").onload = function () {					alert ("somewhere.html is completely loaded");				}			}			window.onload = init;		</script>	</head>	<body>		<div>Something</div>		<iframe src="somewhere.html" id="myframe"></iframe>	</body></html>

It is important to set the onload handler after the main window has loaded. If we tried to do it while the page was loading, the script would not find the iframe, because that part of the document wouldn't have been read yet.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...