簡體   English   中英

通過 Javascript 控制瀏覽器窗口

[英]Controlling browser window through Javascript

我有一個在其他窗口/選項卡中啟動 URL 的網絡應用程序。 我想檢查窗口/選項卡是否存在。 如果沒有,我想創建它,否則我想在第一個位置選擇它。 我使用:

wf=window.open(address, web_form_target, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=640,height=450');
if(wf!=null)
    wf.focus();
                            

但它只有第一次運行良好(在 IE 中,而不是在 Firefox 中)。 如果我在窗口中創建一個新選項卡,當我調用window.open()沒有任何反應。 如果我關閉窗口,它會重新創建它,但會使其保持電離。
有什么方法可以遵循以獲得良好的結果?

提前致謝。

這是我使用了很長時間的一些代碼,據我所知仍然有效。 請注意,oWindow 具有全局作用域,我將它作為字符串傳遞給 open 的第二個參數,而不是作為對象本身。 然后,我在嘗試再次打開之前測試它是否已關閉......如果它已經打開,那么我只關注它:

var oWindow;

function openWindow(p_strURL) {

    if(!oWindow || oWindow.closed) {
        oWindow = window.open(p_strURL, "oWindow", "status, scrollbars, resizable, width=800, height=500");
        if(!oWindow.opener) {
            oWindow.opener    = window;
        }
    }
    else {
        oWindow.location.href = p_strURL;
        oWindow.focus();
    }
}

希望能幫到你找到解決辦法

凱文

web_form_target是窗口名稱。

if (wf.name !==  web_form_target) {
   // create it
}

暫無
暫無

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

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