簡體   English   中英

彈出窗口最大化按鈕

[英]Popup window Maximize button

如何使用Javascript啟用彈出窗口的最大化和恢復按鈕?

你必須像這樣打開一個彈出窗口:

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

訣竅是使窗口可調整大小。 搜索window.open()函數文檔。

使用我粘貼在底部的代碼,您可以通過在網站界面中創建這些按鈕來模擬這些按鈕。

為了最大限度地提高:保存與當前位置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;
})();

我假設你在談論警報彈出窗口? 使用標准JavaScript無法做到這一點。

您最好的解決方案是嘗試使用為各種JavaScript框架(例如jQuery)開發的許多彈出解決方案,並查看是否可以根據您的特定用途進行定制。

試試這個。 它為我工作......

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

你不能,抱歉 - 至少,不是普遍的。 彈出窗口是依賴於實現的,並且沒有任何標准的JavaScript方法可以按照您描述的方式對其進行控制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM