JavaScript Tutorial/HTML Tags/body

Материал из Web эксперт
Перейти к: навигация, поиск

body onload event

   <source lang="javascript">

<html> <head> <title>body onload event</title> <script type="text/javascript" language="javascript">

</script> </head> <body onload="Calculate()"> </body> </html></source>


Body onScroll event

   <source lang="javascript">

<html>

   <head>
       <title>OnScroll Example</title>
   </head>
   <body onscroll="alert("Scrolling")">

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

   </body>

</html></source>


body tag onStop event handler (IE)

   <source lang="javascript">

<html> <head> <title>A Simple Page</title> <script language="JavaScript">

</script> </head> <body onstop="stopped()"> </body> </html></source>


Call your function in body onClick event

   <source lang="javascript">

<html> <head> <title>A Simple Page</title> <script language="JavaScript">

</script> </head> <body onClick="yourMessage()"> </body> </html></source>


document.body.scrollTop

   <source lang="javascript">

<html>

   <head>
       <title>OnScroll Example</title>
       <script type="text/javascript">
           window.onload = function () {
               var oWatermark = document.getElementById("divWatermark");
               oWatermark.style.top = document.body.scrollTop;
           }
       </script>
   </head>

<body>

www.wbex.ru

</body> </html></source>


OnUnload Example

   <source lang="javascript">

<html>

   <head>
       <title>OnUnload Example</title>
   </head>
   <body onunload="alert("Goodbye")">
       Navigate to another page or close the window.
   </body>

</html></source>


Report document.body.scrollLeft and document.body.scrollTop

   <source lang="javascript">

<html>

   <head>
       <title>OnScroll Example</title>
       <script type="text/javascript">
           window.onscroll = function () {
               var oTextbox = document.getElementById("txt1");
               oTextbox.value += "\nscroll is at " + document.body.scrollLeft + " horizontally and " + document.body.scrollTop + " vertically.";
           }
       </script>
   </head>
   <body>

<textarea rows="15" cols="50" id="txt1"></textarea> <P>Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

Try scrolling this window.

   </body>

</html></source>


Use alert dialog in body onresize event

   <source lang="javascript">

<html>

   <head>
       <title>OnResize Example</title>
   </head>
   <body onresize="alert("Resizing")">
   </body>

</html></source>


Use custom function as body onload event handler

   <source lang="javascript">

<html>

   <head>
       <title>Onload Example</title>
       <script type="text/javascript">
           function handleLoad() {
               alert(window.onload);
           }
       </script>
       <body onload="handleLoad()">
       </body>

</html></source>


You cannot set onload function to document.body.onload

   <source lang="javascript">

<html>

   <head>
       <title>Onload Example</title>
       <script type="text/javascript">
           document.body.onload = function () {
               alert("loaded");
           }
       </script>
   </head>
   <body>
   </body>

</html></source>