Run, my JavaScript (3)---javascript Browser object

Source: Internet
Author: User

Window Object1. Is the core of the BOM, the window object points to the current browser window, one of the top level objects. 2. All JavaScript global objects, functions, and variables automatically become members of the Window object3. Global variables are properties of the Window object4. The global function is a method of the Window object5.window Sizewindow.innerhright/window.innerwidth, Interior height/width of the browser window6.window Methodwindow.open () Open a new windowwindow.close () close windowTimermainly refers to the timing events, using JavaScript, we have the ability to execute the code after a set interval, rather than being executed immediately after the function is called .1. Timing Methodsetinterval (); INTERVAL specifies the number of milliseconds to execute the specified code repeatedlyclearinterval (); Stop SetInterval () methodsetTimeout (); Executes the specified code after pausing the specified number of millisecondscleartimeout (); Stop settimeout () methodonce encountered an interview problem, but also to examine this knowledgeXiao Yin is a cute puppy (dog), it sounds very good (wow), every time you see the owner will be a nice call (Yelp). The following objects can be obtained from this description:
<span style= "FONT-SIZE:14PX;" > Function Dog () {        this.wow = function () {            alert ("Wow");        }        This.yelp = function () {            this.wow ();        }    } </span>
python and Xiao Yin, originally also a lovely puppy, but suddenly one day crazy (MadDog), see people will every half a second call (WOW) constantly called (Yelp). According to the description, the code is implemented in the form of an example (hint: Inherit, prototype, setinterval)
<span style= "FONT-SIZE:14PX;" >function MadDog () {        this.yelp = function () {            var = this;     Inherit            setinterval (function () {                self.wow ();            },500);        }    }    Maddog.prototype = new Dog ();      Declaration prototype    var dog = new Dog ();    Dog.yelp ();    var maddog = new Maddog ();    Maddog.yelp ();</span>
of course, we can do this without inheriting or prototyping, so we can:
<span style= "FONT-SIZE:14PX;" >   var yelp = function () {            alert ("Wow");            var wow = setTimeout (function () {                Yelp ();            },500);        }    Yelp ();</span>
directly invoke the method, or you can directly implementHistory Objectthe Window.history object contains a collection of browser history (URLs)History.back (); Same as clicking Back button in browserHistory.forward (); Same as clicking the button in the browser forwardHistory.go (); Go to a page in historyWe often encounter such a situation, when we are browsing the site, some content needs we login to continue to browse (spit slot Baidu Bar, if not landing, only stay on the first page, simply no love), when we landed successfully, will return to the page we browsed before. So how do we make it happen?
<span style= "FONT-SIZE:14PX;" ><body>< before!--browsing interface--><a href= "test1.html" > Jump </a></body><body><!-- Login interface--><form>    <input type= "text" id= "username" ></form><button id= "btn" onclick= "demo () > Submit </button><script>    function Demo () {        var name = document.getElementById ("username"). Value ;        if (name = = "L") {            history.go ( -1);        } else {            alert ("Username entered incorrectly, please reenter!") ");        }    } </script></body></span>
Location ObjectThe window.location object is used to get the address (URL) of the current page and redirect the browser to a new pageObject PropertiesLocation.hostname Returns the domain name of the web hostLocation.pathname returns the path and file name of the current pageLocation.port Returns the port of the web hostLocation.protocol returns the Web protocol usedlocation.href Returns the URL of the current pagelocation.assign () method to load a new document(converted with innerHTML)
<span style= "FONT-SIZE:14PX;" >location.assign ("http:\\www.baidu.com");</span>
Screen ObjectThe Window.screen object contains information about the user's screen, focusing on the suitability of different screens and helping the developer's layoutPropertiesscreen.availwidth/screen.availheight Width/height of the available screenScreen.width/screen.height width/height of the screen
JavaScript Object-orientedUnderstanding Object-oriented(1) The object of all things(2) object has encapsulation and inheritance characteristics(3) information hidingNext, let's look at the object-oriented writing style one
<span style= "FONT-SIZE:14PX;" >/** * Created by PC on 2015/8/27. */(function () {    function person () {        this.name = name;    }    Person.prototype.say = function () {     //prototype        alert ("Hello");    }    Window.person = person;      Information call, execution within a closure} ());       Information encapsulation function Student () {    this.name = name;} /* Subclass Call Parent class Method */student.prototype = new person ();   Inherit/* Parent class Back tone class method */var per = Student.prototype.say; Student.prototype.say =  function () {    per.call (this);    Alert ("Stu-hello");} var stu = new Student (); Stu.say ();</span>
writing style
<span style= "FONT-SIZE:14PX;" >/** * Created by PC on 2015/8/27. */(function () {    function person () {        var _this = {};        _this.name = name;        _this.say = function () {            alert ("Hello");        }        return _this;    }    Window.person = person;} ());       Information encapsulation function Student () {    var _this = person ();    /* Parent Class Callback class method */    var per = _this.say;    _this.say =  function () {        per.call (this);        Alert ("Per-hello");    }    return _this;} /* Subclass calls the parent class method */var Stu = new Object (); Stu.say ();</span>







Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Run, my JavaScript (3)---javascript Browser object

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.