js弹出窗体

js 弹出窗体语法及参数详解

js:

    <script type="text/javascript">
        function openEg(url, width, height, left, top) {
            var temp = "channelmode=no,location=no,menubar=no,toolbar=no,directories=no,scrollbars=no,resizable=no";
            if (width) {
                temp += ',width=' + width;
            } else {
                width = 0;
            }
            if (height) {
                temp += ',height=' + height;
            } else {
                height = 0;
            }
            if (left) {
                temp += ',left=' + left;
            } else {
                temp += ',left='
    + Math.round((window.screen.width - parseInt(width)) / 2);
            }
            if (top) {
                temp += ',top=' + top;
            } else {
                temp += ',top='
    + Math.round((window.screen.height - parseInt(height)) / 2);
            }
            window.open(url, '_blank', temp);
        }
    </script>

HTML:

<div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="openEg('Default2.aspx',700,600)" />
  </div>

弹出的窗体left和top不赋值的话,默认居中!

该方法不支持360!

原文地址:https://www.cnblogs.com/fuge/p/2607869.html