How JavaScript makes pop-up windows in the center of the screen

Source: Internet
Author: User
Javascript

How do I use JavaScript to open a window? It is an insult to the wisdom of our web programmers!

However, today, users put forward a new demand, he will pop out of the window to be in the middle of the entire screen!

So, Google, find a lot of people reprinted articles as follows:

<script language= "JavaScript" >
var  s = "";
S + + Web page visible area wide: + document.body.clientWidth;
S + + "Web page visible Area High:" + document.body.clientHeight;
S + + page visible area wide: "+ document.body.offsetwidth  +" (including Edge and scroll bar width);
S + + page visible Area High: "+ Document.body.offsetHeight +" (including the edge of the width);
S + + page body Full text width: "+ document.body.scrollWidth;
S + = "The full text of the page is high:" + document.body.scrollHeight;
S + + pages are rolled High: "+ document.body.scrollTop;" The
S + + page is rolled away to the left: "+ document.body.scrollLeft;"
S + + page body part: "+ window.screentop;"
S + + page body part left: "+ window.screenleft;"
S + = "high screen resolution:" + window.screen.height;
S + + screen resolution width: + window.screen.width;
S + + screen available Workspace height: + window.screen.availHeight;
S + + screen available workspace width: + window.screen.availWidth;
S + + "your screen setting is" + window.screen.colorDepth + "bit color";
S + + "your screen settings" + Window.screen.deviceXDPI + "pixel/inch";
Alert (s);
</SCRIPT>
This article is not difficult to write code that opens the window in the middle of the screen:

function Openbrwindowincentre (theurl,width,height) {
var left, top;
left = (window.screen.availwidth-width)/2;
top = (window.screen.availheight-height)/2;
var per = ' width= ' + width + ', height= ' + height + ', left= ' + Left + ', top= ' + Top + ', screenx= ' + Left + ', screeny= ' + to P
window.open (theURL, "", per);
}
In the code, because the pop-up window is not too large, no processing pop-up window than the large screen, we recommend that you modify the actual situation.



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.