寻找答案,并一直在试验但无济于事。我有一个下拉链接,在选择选项时自动打开弹出页面,但我无法弄清楚如何使弹出窗口居中。任何帮助表示赞赏:
<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>
答案 0 :(得分:0)
获取屏幕宽度和屏幕高度:
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();
}
}