【问题标题】:Popup window Maximize button弹出窗口最大化按钮
【发布时间】:2011-01-04 04:06:16
【问题描述】:

如何使用Javascript启用弹出窗口的最大化和恢复按钮?

【问题讨论】:

    标签: javascript popupwindow


    【解决方案1】:

    您不能,抱歉 - 至少,不是普遍的。弹出窗口依赖于实现,没有任何标准的 JavaScript 方法可以按照您描述的方式控制它。

    【讨论】:

      【解决方案2】:

      我假设您在谈论警报弹出窗口?这是标准 JavaScript 无法做到的。

      您最好的解决方案是尝试使用为各种 JavaScript 框架(例如 jQuery)开发的许多弹出解决方案中的一些,并查看是否可以根据您的特定用途进行调整。

      【讨论】:

        【解决方案3】:

        使用我粘贴在底部的代码,您可以通过在您的网站界面中创建这些按钮来模拟这些按钮。

        最大化:用Namespace.outerPositionGet()保存当前位置,用Namespace.outerSizeGet()保存大小,然后使用Namespace.outerPositionSet({left:0,top:0})Namespace.outerSizeSet({width:window.screen.availWidth, height:window.screen.availHeight})

        恢复:只需设置最大化时保存的位置和大小。

        var Namespace = (function() {
            var N, W, framePosition, frameChrome, setFramePosition, setFrameChrome;
            N = {};
            W = window;
            setFramePosition = function() {
                var tmp0;
                if (typeof framePosition !== 'undefined') {
                    return;
                }
                tmp0 = {
                    top : W.screenTop,
                    left : W.screenLeft
                };
                W.moveTo(tmp0.left, tmp0.top);
                framePosition = {
                    top : tmp0.top - W.screenTop,
                    left : tmp0.left - W.screenLeft
                };
                W.moveTo(tmp0.left + framePosition.left, tmp0.top + framePosition.top);
            };
            setFrameChrome = function() {
                var tmp0, tmp1;
                if (typeof frameChrome !== 'undefined') {
                    return;
                }
                tmp0 = N.innerSizeGet();
                W.resizeTo(tmp0.width, tmp0.height);
                tmp1 = N.innerSizeGet();
                frameChrome = {
                    width : tmp0.width - tmp1.width,
                    height : tmp0.height - tmp1.height
                };
                W.resizeTo(tmp0.width + tmp1.width, tmp0.height + tmp1.height);
            };
            N.outerPositionSet = function(position) {
                W.moveTo(position.left, position.top);
            };
            N.outerPositionGet = function() {
                if (typeof W.screenTop !== 'undefined') {
                    setFramePosition();
                    N.outerPositionGet = function() {
                        return {
                            top : W.screenTop + framePosition.top,
                            left : W.screenLeft + framePosition.left
                        };
                    };
                } else if (typeof W.screenY !== 'undefined') {
                    N.outerPositionGet = function() {
                        return {
                            top : W.screenY,
                            left : W.screenX
                        };
                    };
                } else {
                    N.outerPositionGet = function() {
                        return {
                            top : 0,
                            left : 0
                        };
                    };
                }
                return N.outerPositionGet();
            };
            N.outerSizeSet = function(size) {
                W.resizeTo(size.width, size.height);
            };
            N.outerSizeGet = function() {
                if (W.outerWidth) {
                    N.outerSizeGet = function() {
                        return {
                            width : W.outerWidth,
                            height : W.outerHeight
                        };
                    };
                } else {
                    setFrameChrome();
                    N.outerSizeGet = function() {
                        var size;
                        size = N.innerSizeGet();
                        size.width += frameChrome.width;
                        size.height += frameChrome.height;
                        return size;
                    };
                }
                return N.outerSizeGet();
            };
            N.innerSizeSet = function(size) {
                setFrameChrome();
                N.innerSizeSet = function(size) {
                    W.resizeTo(size.width + frameChrome.width, size.height + frameChrome.height);
                };
                N.innerSizeSet(size);
            };
            N.innerSizeGet = function() {
                if (typeof W.innerHeight === 'number') {
                    N.innerSizeGet = function() {
                        return {
                            width : W.innerWidth,
                            height : W.innerHeight
                        };
                    };
                    return N.innerSizeGet();
                }
                var isDocumentElementHeightOff, node;
        
                isDocumentElementHeightOff = function() {
                    var div, r;
                    div = W.document.createElement('div');
                    div.style.height = "2500px";
                    W.document.body.insertBefore(div, W.document.body.firstChild);
                    r = W.document.documentElement.clientHeight > 2400;
                    W.document.body.removeChild(div);
                    return r;
                };
        
                if (typeof W.document.clientWidth === 'number') {
                    node = W.document;
                } else if ((W.document.documentElement && W.document.documentElement.clientWidth === 0) || isDocumentElementHeightOff()) {
                    node = W.document.body;
                } else if (W.document.documentElement.clientHeight > 0) {
                    node = W.document.documentElement;
                }
                N.innerSizeGet = function() {
                    return {
                        width : node.clientWidth,
                        height : node.clientHeight
                    };
                };
                return N.innerSizeGet();
            };
            return N;
        })();
        

        【讨论】:

          【解决方案4】:

          你必须像这样打开一个弹出窗口:

          window.open('url', 'windowname', 'location=0, status=0, resizable=1, scrollbars=1, width=400, height=400');
          

          诀窍是使窗口可调整大小。搜索 window.open() 函数文档。

          【讨论】:

            【解决方案5】:

            也试试这个。它对我有用...

             window.open('fileURL','status=1,directories=1,menubar=0,toolbar=0,
                          scrollbars=1,titlebar=0,dialog=1)
            

            【讨论】:

              猜你喜欢
              • 2021-05-02
              • 2021-03-21
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-08-26
              • 2011-05-14
              • 2020-09-25
              相关资源
              最近更新 更多