並且謝謝大家誰去分享他們的想法的麻煩。
我解決了這個問題通過以下方式:
當從首頁導航到新的窗口下面的JavaScript來打開一個新窗口:
function popupFull(url)
// For explanation of this code see: http://www.quirksmode.org/js/popup.html
// Note: If fullscreen = 1 you can't see the menubar, toolbar, status etc.
// It is advisable to have no spaces around the commas in the parameters.
{
//alert("Opening: " + url)
// Prepare the parameter string
params = 'width='+screen.width;
params += ',height='+screen.height;
params += ',top=0,left=0';
params += ',fullscreen=0';
params += ',menubar=0';
params += ',toolbar=0';
params += ',directories=0';
params += ',status=0';
params += ',scrollbars=0';
params += ',resizable=1';
// Open a new window.
newWin=window.open(url, "fullWindow", params);
// If the current Window is in focus, switch focus to the new Window.
if (window.focus)
{
newWin.focus()
}
// Return the new Window object reference.
return newWin;
}
所以新的窗口可以成爲打開並且我已經打開了主窗口,但是沒有關注新窗口的焦點。
在新窗口中有一個「菜單」按鈕。點擊這個調用下面的JavaScript函數:
function openMenu(winURL, winName, winFeatures)
{
// Create a reference of the Window which opened this Window. This should be
// the Main Menu Window.
var winObj=window.opener;
var menuOuterWidth = 1080;
var menuOuterHeight = 896;
var menuInnerWidth = 1068;
var menuInnerHeight = 767;
var menuX = (screen.width - menuOuterWidth)/2;
var menuY = (screen.height - menuOuterHeight)/2;
// Prepare the parameter string for re-opening the Menu
params = 'width='+menuInnerWidth;
params += ',height='+menuInnerHeight;
params += ',top='+menuY+',left='+menuX;
params += ',fullscreen=0';
params += ',menubar=1';
params += ',toolbar=1';
params += ',status=1';
params += ',scrollbars=1';
params += ',location=1';
params += ',resizable=1';
try
{
// Check to see if the window reference already exists.
if (winObj)
{
// Check to see if the Menu window is closed.
if (winObj.closed)
{
// The Menu window is closed.
// Open the Menu Window.
winObj = window.open(winURL, winName, params);
// Close this Course Window.
window.close();
// Return the Menu Window object reference should the caller want it.
return winObj;
}
else
{
// The Menu Window has not been closed. Set the Window's size and position.
// Note: When resizing the outerWidth/outerHeight value has to be passed.
winObj.window.resizeTo(menuOuterWidth, menuOuterHeight);
winObj.window.moveTo(menuX, menuY);
// Bring it into focus (bring to front).
winObj.focus();
// Close this Course Window.
window.close();
// Return the Menu Window object reference should the caller want it.
return winObj;
}
}
else
{
// The winObj object does not exist. Open the Menu.
winObj = window.open(winURL, winName, params);
// Close this Course Window.
window.close();
// Return the Menu Window object reference should the caller want it.
return winObj;
}
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
//alert(txt);
// When IE6 tries to obtain the winObj.closed property, when the window is closed, it can cause
// an error "Permission Denied". This error is caught here. Open the Menu.
// Open the Menu Window.
winObj = window.open(winURL, winName, params);
// Close this Course Window.
window.close();
// Return the Menu Window object reference should the caller want it.
return winObj;
}
}
的意見應說明一切。關鍵是要獲得我們開始的主頁窗口的參考。 (var winObj=window.opener;
)。
讓我頭疼的是,如果我打開新窗口(使用IE6),切換回主頁並關閉主窗口,然後在新窗口中點擊'菜單'按鈕,什麼也沒有發生!我嘗試了一切,然後在喝了一杯茶之後,意識到我絕不會在任何應用程序中編寫代碼,而無需任何形式的錯誤捕獲。我添加了一個Try,Catch語句,並在「提醒」中報告了錯誤。我收到了'Permission Denied'錯誤。
經過大量的閱讀後,我想我無法消除錯誤,我會盡可能優雅地處理錯誤。這導致了上面的代碼。
它的作品,我希望這可以幫助別人。
打開各種窗口的界面不是很友好 - 考慮一個不同的設計。 – Oded 2010-12-14 17:09:14
您應該能夠通過跟蹤窗口名稱來完成此操作。但不要這樣做。您無法控制瀏覽器顯示新窗口的方式,或者即使它們顯示窗口(換句話說,使用製表符)。你也無法控制窗口焦點策略。總的來說,爲人們開設大量新窗口並不是一個好主意。 – Pointy 2010-12-14 17:09:36
聽@Oded,因爲他說的是實話。 – 2010-12-14 17:11:00