【发布时间】:2010-07-01 10:19:20
【问题描述】:
我想计算打开的新窗口的数量。
但是,当我关闭打开的 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() 打开这些新窗口?
-
是的。使用 window.open() 方法打开新窗口。
标签: javascript jsf