Cross-browser javascript to get the position and size of the window

Source: Internet
Author: User

Cross-browser javascript to get the position and size of the window

Cross-browser location Retrieval

Var leftX = typeof window. screenLeft = 'number '? Window. screenLeft: window. screenX; var topY = typeof window. screenTop = 'number '? Window. screenTop: window. screenY;

Firefox does not support screenLeft and scrennTop, but supports screenX and screenY. ie supports screenLeft and scrennTop, but does not support screenX and screenY.
Cross-browser size acquisition

Var width = window. innerWidth; // window. required because IE does not support var height = window. innerHeight; // if inner is supported, use it. // The method of document object if (typeof width! = 'Number') {if (document. compatMode = 'css1compat') {width = document.doc umentElement. clientWidth; // standard ie height = document.doc umentElement. clientHeight;} else {// non-standard ie width = document. body. clientWidth; height = document. body. clientHeight ;}}

 

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.