Home > Web Front-end > JS Tutorial > JavaScript pop-up window centering code_javascript skills

JavaScript pop-up window centering code_javascript skills

WBOY
Release: 2016-05-16 19:09:38
Original
1010 people have browsed it

[Ctrl A Select All Note: If you need to introduce external Js, you need to refresh to execute
]

javascript popup window centering code

The following are two examples of pop-up windows centered on the screen

The code is as follows:


window.open() method
function ShowDialog( url) {
var iWidth=300; //Window width
var iHeight=200; //Window height
var iTop=(window.screen.height-iHeight)/2;
var iLeft =(window.screen.width-iWidth)/2;
window.open(url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
Width=" iWidth " ,Height=" iHeight ",top=" iTop ",left=" iLeft);
}

window.showModalDialog method

The code is as follows:


function ShowDialog(url) {
var iWidth= 300; //Window width
var iHeight=200;//Window height
var iTop=(window.screen.height-iHeight)/2;
var iLeft=(window.screen.width-iWidth )/2;
window.showModalDialog(url,window,"dialogHeight: " iHeight "px; dialogWidth: " iWidth "px;
dialogTop: " iTop "; dialogLeft: " iLeft "; resizable: no; status : no;scroll:no");
}

Note the second parameter here, window


Users must enter information in this pop-up form before they can access other forms. It is a modal form, so just use the second method

The javascript pop-up window is centered four:

The code is as follows:


function selectCustomer(){
var iTop = (window.screen.availHeight-30-500)/2;
var iLeft = (window.screen.availWidth-10-750)/2;
window.open("../ customer/creditApprManage.do?method=toGetCustomer",
"searchCorp",
"height=500,width=750,top=" iTop ",left=" iLeft ",toolbar=no,menubar=no, scrollbars=auto,resizeable=no,location=no,status=no"
);
}

Note: 500 and 750 are hard-coded and can be passed in through parameters.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template