Demonstration of some windon functions in JavaScript

Source: Internet
Author: User

Demonstration of some windon functions in JavaScript
1. Use of onload and onunload onbeforeunload

 <Script type = text/javascript src = 1.js> </script> <Script type = text/javascript> onload = function () {// event sets the actions performed during page loading, that is, the Action alert (onload...) executed when you enter the page ...);} onunload = function () {// you have read the new page to be loaded from the server, when the current page is about to be replaced, the call // is generally used to set the action to be executed after the page is left. Alert (onunload ....);} onbeforeunload = function () {// It is called when you are going to go to the server to read a new page. At this time, you have not started reading the page. In short, it is before leaving the page, generally, you are reminded to ask if you want to leave this page. Alert (onbeforeunload ...)} // nunload and onbeforeunload are both actions before page refreshing and closing, but onbeforeunload is prior to onunload and // Onunload cannot prevent page updating and closing. Onbeforeunload can achieve </script> This is the div field. go Baidu 

2. navigator, history, and location

 

 

 <Script type = text/javascript src = 1.js> </script> <script type = text/javascript> function getBrowser () {var m1 = window. navigator. appCodeName; // appCodeName obtains the code name of the browser. Var m2 = window. navigator. appName; // obtain the browser name. // Var m3 = navigator. cpuClass; // obtain the string indicating the CPU level. Var m4 = window. navigator. cookieEnabled; // obtain whether the client's permanent cookie is enabled in the browser. Permanent cookies are stored on client computers. Println (get the code name of the browser: + m1); println (get the name of the browser: + m2); // println (get the string indicating the CPU level: + m3 ); println (obtain whether the client's permanent cookie is enabled in the browser. Permanent cookies are stored on client computers. : + M4);} function windowsobj () {var pro = location. protocol; // set or obtain the URL protocol section println (pro); // filevar text = location. href; // set or obtain the entire URL as a string. Location. href = http://www.baidu.com;} </script>  






 

 

3. Specific applications of Window: Jitter, moving Window, and Timer
  <Script type = text/javascript src = 1.js> </script> <script type = text/javascript> function f1 () {alert (time ....);} function f2 () {var a = confirm (Are you sure); println (a: + a);} function f3 () {var bb = setTimeout (alert ('timeout... '), 2000);} function f4 () {for (var I = 0; I <100; I ++) {// browser window ---- relatively mobile, move to the lower right corner (move 10 pixels horizontally and vertically) moveBy (20, 0); moveBy (-20, 0); moveBy (0,-20 );}} // setInterval (alert ('setinterval time -- '), 10) calculates an expression after a specified millisecond value. Function f5 () {var aa = setInterval (alert ('setinterval time -- '), 1300); // set the frequency} function f6 () {var ss = clearInterval ();} </script>      


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.