Javascript 使用onChange将弹出窗口居中
环顾四周寻找答案,一直在试验,但都没有结果。我有一个下拉链接,当选择一个选项时,它会自动打开一个弹出页面,但我不知道如何使弹出窗口在屏幕中居中。感谢您的帮助:Javascript 使用onChange将弹出窗口居中,javascript,Javascript,环顾四周寻找答案,一直在试验,但都没有结果。我有一个下拉链接,当选择一个选项时,它会自动打开一个弹出页面,但我不知道如何使弹出窗口在屏幕中居中。感谢您的帮助: <html> <script language="JavaScript"> function goto(objSel) { if (objSel.selectedIndex > 0) { win = window.open(objSel.options[objSel.selectedIndex].va
<html>
<script language="JavaScript">
function goto(objSel) {
if (objSel.selectedIndex > 0) {
win = window.open(objSel.options[objSel.selectedIndex].value ,'','width=640, height=480, top=200, left=500, scrollbars=no, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no, dependent=no');
win.focus();
}
}
//-->
</script>
<form name="cityselect">
<select name="menu" onchange="goto(this)" size="1">
<option selected="selected">Select One</option>
<option value="http://www.leeds.com">Leeds</option>
<option value="http://www.manchester.com">Manchester</option>
</select>
</form>
</html>
函数goto(objSel){
如果(objSel.selectedIndex>0){
win=window.open(objSel.options[objSel.selectedIndex].value',,'width=640,height=480,top=200,left=500,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,dependent=no');
win.focus();
}
}
//-->
选择一个
利兹
曼彻斯特
只需获取屏幕宽度和屏幕高度:
function goto(objSel) {
if (objSel.selectedIndex > 0) {
var topVar = Math.floor((screen.height - 480)/2);
var leftVar = Math.floor((screen.width - 640)/2);
var strOptions = "width=640, height=480, top=" + topVar + ", left=" + leftVar + ", scrollbars=no, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no, dependent=no";
win = window.open(objSel.options[objSel.selectedIndex].value ,'',strOptions);
win.focus();
}
}
非常感谢你!很好!