弹出窗口最大化按钮

发布于 2024-08-18 02:56:49 字数 37 浏览 2 评论 0原文

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

How to enable the maximize and restore button of the popup window using Javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

原谅我要高飞 2024-08-25 02:56:49

您必须打开这样的弹出窗口:

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

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

You have to open a popup like this:

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

The trick is to make the window resizable. Search for the window.open() function documentation.

面犯桃花 2024-08-25 02:56:49

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

最大化:使用 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;
})();

Using the code I pasted on the bottom, you can emulate these buttons by creating them in your website interface.

To maximise: save the current position with Namespace.outerPositionGet() and size with Namespace.outerSizeGet(), then do Namespace.outerPositionSet({left:0,top:0}) and Namespace.outerSizeSet({width:window.screen.availWidth, height:window.screen.availHeight}).

To restore: just set position and size which were saved when maximising.

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;
})();
獨角戲 2024-08-25 02:56:49

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

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

I'm assuming you're talking about the alert popup? This can't be done with standard JavaScript.

You best solution would be to try using some of the many popup solutions that have been developed for the various JavaScript frameworks (e.g. jQuery), and seeing if you can tailor this to your particular use.

开始看清了 2024-08-25 02:56:49

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

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

try this also. its working for me...

 window.open('fileURL','status=1,directories=1,menubar=0,toolbar=0,
              scrollbars=1,titlebar=0,dialog=1)
半暖夏伤 2024-08-25 02:56:49

抱歉,你不能——至少不能普遍如此。弹出窗口取决于实现,并且没有任何标准 JavaScript 方法可以按照您描述的方式控制它。

You can't, sorry - at least, not universally. The popup is implementation-dependent and there aren't any standard JavaScript methods for controlling it in the manner you describe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文