Javascript-based window, screen, and Navigator objects

Source: Internet
Author: User
A) First, let's take a look at several coordinate systems: 1> screen coordinates describe the location of a browser window on the desktop. They are measured relative to the upper left corner of the desktop. 2> the window coordinates describe the positions of the video ports in the web browser. They are measured relative to the upper left corner of the view. 3> the coordinates in the document describe the positions in an HTML document. They are measured relative to the upper left corner of the document. Document coordinate acquisition window position: var getwinposition = function () {var Pos = {// window. screenx => ffleft :( typeof window. screenleft = 'number ')? Window. screenleft: window. screenx; top :( typeof window. screentop = "Number ")? Window. screentop: window. screeny ;}; return POS ;}to get the Page View Size: var getviewportsize = function () {var W = Window. innerwidth, H = widnow. innerheight; If (typeof W! = "Number") {// ieif (document. compatmode = "css1compat") {// standard Mode w = document.doc umentelement. clientwidth; H = document.doc umentelement. clientheight;} else {// none in IE6 in hybrid mode <! Doctype> declare W = document. body. clientwidth; H = document. body. clientheight ;}}return {width: W, height: H} B) The Screen Object provides information about the display size and color Quantity, indicating the availheight screen height (excluding the taskbar) availwidth screen width (excluding the taskbar) bufferdepth setting or obtaining the pixel bits of the bitmap buffer color colordepth getting the pixel bits of the color used for the destination setting or the buffer devicexdpi setting or getting the actual deviceydpi setting or getting the value of each inch in the horizontal direction of the System screen the actual dot value fontsmoothingenabled in the vertical direction of the System screen per inch to get whether the user has enabled the option of "height" in the display settings to get the vertical resolution of the screen logicalxdpi to get the system screen level per inch Regular point value logicalydpi get System screen vertical regular point value updateinterval per inch set or get screen update interval width get screen vertical resolution get screen (excluding taskbar) Size: vaR getscreensize = function () {var W = screen. availwidth, H = screen. availheight; return {width: W, height: H} c) the navigator object contains all information about the browser. var getbrowsermessage = function () {var nav = navigator; Return "appname: "+ nav. appname + "\ n" + // simple browser name "appcodename:" + nav. appcodename + "\ n" + // the browser code name "appversion:" + nav. appvers Ion + "\ n" + // browser version "useragent:" + nav. useragent + "\ n" + // the string "Platform:" + nav. platform; // hardware platform for running the browser} // ffappname: netscapeappcodename: mozillaappversion: 5.0 (Windows) useragent: Mozilla/5.0 (Windows NT 5.1; RV: 21.0) gecko/20100101 Firefox/21.0 platform: win32var pattern =/(Mozilla )(? :.*? RV :( [\ W.] +) |) // ie6.0appname: Microsoft Internet Explorer appcodename: Mozilla appversion: 4.0 (compatible; MSIE 6.0; Windows NT 5.1; infopath.2 ;. net4.0c) useragent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; infopath.2 ;. net4.0c) platform: Win32 var pattern =/(MSIE) ([\ W.] +) // chormeappname: Netscape appcodename: Mozilla appversion: 5.0 (Windows NT 5.1) applewebkit/537.11 (khtml, like gecko) Chrome/23.0.20.1.97 Safari/537.11 useragent: Mozilla/5.0 (Windows NT 5.1) applewebkit/537.11 (khtml, like gecko) Chrome/23.0.20.1.97 Safari/537.11 platform: win32var pattern =/(chrome) [\/] ([\ W.] +) // operaappname: Opera appcodename: Mozilla appversion: 9.80 (Windows NT 5.1; U; ZH-CN) useragent: Opera/9.80 (Windows NT 5.1; U; zh-CN) presto/2.10.289 version/12.02 platform: win32var pattern =/(opera )(? :. * Version |) [\/] ([\ W.] +) // safariappname: Netscape appcodename: Mozilla appversion: 5.0 (Windows NT 5.1) applewebkit/534.54.16 (khtml, like gecko) version/5.1.4 Safari/534.54.16 useragent: mozilla/5.0 (Windows NT 5.1) applewebkit/534.54.16 (khtml, like gecko) version/5.1.4 Safari/534.54.16 platform: win32var pattern =/(WebKit) [\/] ([\ W.] +)/; obtain the browser version: var getbrowser = function (UA) {UA = UA. tolowerca Se (); var match =/(chrome) [\/] ([\ W.] + )/. exec (UA) |/(WebKit) [\/] ([\ W.] + )/. exec (UA) |/(opera )(? :. * Version |) [\/] ([\ W.] + )/. exec (UA) |/(MSIE) ([\ W.] + )/. exec (UA) | UA. indexof ("compatible") <0 &/(Mozilla )(? :.*? RV :( [\ W.] +) | )/. exec (UA) | []; return {Browser: Match [1] | "", version: Match [2] | "0 "};}; vaR nav = getbrowser (navigator. useragent); alert (NAV. browser + "----" + nav. version); d) return to the top window. location. hash = "# Top"; orwindow. location. replace ("# Top ");

Related Article

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.