带有滚动条的 JavaScript 弹出窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16806406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:03:10  来源:igfitidea点击:

JavaScript popup window with scrollbars

javascriptscrollbar

提问by xjshiya

I have a function that pops up window in the center and I want it to have a vertical scrollbar.

我有一个在中心弹出窗口的功能,我希望它有一个垂直滚动条。

function popUpCal()
{
    var url = "calendar_flight_maint.php";
    var width = 700;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
window.open(url, "subWind", windowFeatures, "POS", "toolbar=no", "scrollbars=1");
}

I have tried scrollbars=yes, scrollbars=auto, scrollbars=1but the scrollbars still aren't appearing. Is there something wrong with my code? I'm using Firefox 21.0 and I've already tested it in IE 8. What seems to be the problem?

我试过scrollbars=yes, scrollbars=autoscrollbars=1但滚动条仍然没有出现。我的代码有问题吗?我使用的是 Firefox 21.0 并且我已经在 IE 8 中测试过它。似乎是什么问题?

回答by RienNeVaPlu?s

As seen in the specs for window.open, your parameters are wrong. Try this:

正如window.open的规格中所见,您的参数是错误的。试试这个:

function popUpCal()
{
    var url = "calendar_flight_maint.php";
    var width = 700;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height +   
        ",status,resizable,left=" + left + ",top=" + top + 
        "screenX=" + left + ",screenY=" + top + ",scrollbars=yes";

    window.open(url, "subWind", windowFeatures, "POS");
}

Here is a jsFiddle

这是一个jsFiddle