Jump to content

Window.onload Question - Solved With Thanks


niche

Recommended Posts

I want to understand this script. I can't find a reference that that says onload is a property of window. Am I thinking about this correctly?

<script type="text/javascript">			window.onload=function(){				var strTesterO = document.getElementById('strTester')				var str = "The cow jumped over the moon";				var spanO = document.createElement('span');				spanO.id = 'mySpan'				spanO.appendChild(document.createTextNode(str));				strTesterO.appendChild(spanO);				alert(document.getElementById('mySpan').clientWidth + "\n"+document.getElementById('mySpan').clientHeight);			}		</script>

Link to comment
Share on other sites

The window and image object have an onload event. I don't think that, by standards, other elements have it, but all browsers support the onload event on frame elements.

Link to comment
Share on other sites

I'm still at a point in my javascript that I need to see the reference, but I haven't found one on w3s that defines window.onload. Can you send me a link? I'm bothered by not being able to find the ref on my own.

Link to comment
Share on other sites

Thanks. Using your last post, I changed the script, in post #1 to:(changed window.onload=function(){ to function load(){and<body> to <body onload="load()"> ) It looks good to me. Did I create a new issue in your opinion?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">	<head>		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />		<title></title>		<style type="text/css">			#mySpan{				display: table-cell;				font-family: arial;				font-weight: bold;				font-size: 2em;			}		</style>		<script type="text/javascript">			function load() {				var strTesterO = document.getElementById('strTester')				var str = "The cow jumped over the moon";				var spanO = document.createElement('span');				spanO.id = 'mySpan'				spanO.appendChild(document.createTextNode(str));				strTesterO.appendChild(spanO);				alert(document.getElementById('mySpan').clientWidth + "\n"+document.getElementById('mySpan').clientHeight);			}		</script>	</head>	<body onload="load()">		<div id="strTester"></div>	</body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...