Understanding The JavaScript Event Model (part 2) - How's The Weather Up There? (Page 3 of 10 )
The "height" and "width" properties return the height and width of the window or frame containing the generated event. Here's how it works:
In this example, on clicking the form button an alert box appears, stating the height of the document:
<html>
<head>
</head>
<body>
<form>
<input type="button" value="Click Me" onClick="alert('This document is '
+ document.height + ' pixels tall')"> </form>
</body>
</html>
Or you could even do this:
<html>
<head>
<script language="JavaScript">
function changeWidth()
{
document.width=40
}
</script>
</head>
<body>
<form>
<input type="button" value="Click Me" onClick="changeWidth()"> </form>
This is a really, really, really, really, really, really, really,
really, really, really, really, really, really, really, really, really,
really, really, really long string.
</body>
</html>
Now, when you click the button, you'll see that the document width reduces to 40 pixels, and the incredibly long sentence gets cropped to exactly that width.
Before you get all excited, though, you should know that the "width" and "height" properties only work in Netscape Navigator 4.x.
Next: X Marks The Spot >>
More JavaScript Articles
More By Team Melonfire, (c) Melonfire