You are on page 1of 8
aa JAVASCRIPT ay KIT Soon e@ Ccalogores: All | Free J8/Appita | Tutoriale References Home | | Free Javascripts || Tutorial References ¥ | | Developer Courses | | CSS Examples REFERENCE LIST JavaScript Operators + Auimetic operators + Assignment operators + Bitwise operators + Comparison! Looie + Other operators + Operator Procedence JavaScript Statements + Conditionals + Looping Global functions JavaScript Events Escape Sequences Reserved Words Alex (XMLHttpRequest) Anchor Applet Acca Aray Boolean Date Document Image JSON object Link Location viv EM JavaScript Kit > JavaScript Reference > Here Window Object Last updated: May 20th, 2014 ‘The Window object is the top level object in JavaScript, and contains in itself several other objects, such as "document", “history” etc. Related Tutorials Windows and JavaScript Loading two frames with one link Determining whether a browser window is open Moving, scrolling, and resizing browser window. ‘The onerror event of the window object. ‘Creating a live CSS clock using CSS3 and requestAnimationFrame() Filter by Property/ Method: @ Events onblur Fires when the window loses focus. jonerror Fires when a JavaScript error occurs. By returning erve inside this event, JavaScript errors on the page (if any) are suppressed, with no error messages popping up: window.onerror-function (mag, url, Linenunber) { var logerror="Brror message: | + mag +". Url: ! + url + ‘tine Nunber: ' + linenumber alert (Logerror) ) ISee “The onerror event of the window object” for full details. onfocus Fires when the focus is set on the current window. onload Fires when the page has finished loading, including images. This is a popular event to use to run some JavaScript once everything on the page has loaded? is available: | window ontoad-function()¢ ‘runsonefunction () ) Math Navigator [The limitation with the above approach js that multiple calls to window.ontoad on the same page causes all but the last one to be adopted, |with each proceeding call overwritten by the one following it. On a page ]with multiple JavaScripts, this is more likely than not to happen. To lovercome this, you can invoke the ontoaa event handler using the DOM methods etenent.addtventiistener() and its counterpart etenent.attachevent( in IE, Event handlers defined in this manner will not get overwritten by their counterparts, but instead queued. Fires when the window is resized lonscralt Fires when the window is scrolled. The following shows the current y [coordinate of the upper left corner of the viewable window in the browser's title bar when the page is scroll window-onseroll-function (){ var scrollY=window.pageYOffset || document body. scroliTop document.title-serellY lonbeforeunload Fires when the page is about to be unloaded, prior to window.onunloae levent firing. Supported in all modern browsers. By setting event.returnvaiue to a string, the browser will prompt the user whether he/she wants to leave the current page when attempting to: window. onbeforeunload-function(e) | e.returnValue="Any return string here forces a dialog to appear when user leaves this page" ) window. location"hetp://eme. google.com" //pronpt is invoked lonuntoad Fires when the page is unloaded- process cannot be overruled at this point. Often used to run code cleanup routines. Properties closed Returns the Boolean variable indicating whether window has been closed jor not. Also see: “Determining whether a browser window is open or not" defaultStatus Read/write property that reflects the default window status bar message that appears. document Reference to the current document object. frames [An array referencing all of the frames in the current window, including Frac elements. Use franes.tength to probe the number of frames. The {following changes the src property of every IFRAME on the page to a lank page: