我想統計打開的新窗口的數量。如何計算打開newwindows?
但是,當我關閉打開的newWindow,然後減少窗口計數。
我的新窗口已有closelink也。
可能是我選擇使用closelink或瀏覽器關閉窗口。
更新
如果我開了2個新的窗口,那麼我估計當前打開的窗口。但是,如果我關閉使用的任何窗口(關閉鏈接或瀏覽器關閉窗口),現在只打開一個新窗口。
在這裏,我不知道,如何顯示打開的窗口數爲1
共4個文件是:MainPage.jsp,newwindow1.jsp,newwindow2.jsp和windowcount .js文件
MainPage.jsp
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<a4j:loadScript src = "windowcount.js" />
</head>
<body>
<h:outputLink value="#" onclick="window.open('newwindow1.jsp','firstwindow','width=600,height=600');addWindowCount();">
<h:outputText value="new Window1"/>
</h:outputLink>
<h:outputLink value="#" onclick="window.open('newwindow2.jsp','secondWindow','width=600,height=600');addWindowCount();">
<h:outputText value="New window 2"/>
</h:outputLink>
<a4j:commandButton value="Get Window Count" onclick="getNewWindowCount();"/>
</body>
</html>
newwindow1.jsp
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>First Window</title>
</head>
<body>
<a4j:commandLink id="firstWindowCloseLinkId"
value="Close Window"
onclick="javascript:window.close()"/>
</body>
</html>
newwindow2.jsp
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Second Window</title>
</head>
<body>
<a4j:commandLink id="secondWindowCloseLinkId"
value="Close Window"
onclick="javascript:window.close()"/>
</body>
</html>
個windowcount.js
var countNewWindow = 0;
function addWindowCount()
{
countNewWindow++;
}
function getNewWindowCount()
{
alert("Current opened NewWindow : " + countNewWindow);
}
幫助我這件事。 感謝您的努力。
這些新窗口是由您的代碼使用window.open()打開? – 2010-07-01 10:28:10
是的。使用window.open()方法打開新窗口。 – Eswar 2010-07-02 01:10:27