例:
在按下按钮(NEW)的主页面中,页面将使用Javascript通过调用redirectPage()在新窗口中打开新页面.
在主页面上单击一个按钮(EXIT),然后页面将调用confirmExit(),然后closeChildWindows()关闭所有弹出新窗口,然后重定向到另一个新页面.
但是,如果我刷新主页面,JS变量(childWindowHandles)将始终被重置,这会导致页面在重新定位之前无法关闭所有其他弹出窗口,同时单击EXIT按钮
有谁知道我怎么能解决这个问题?通过能够保持JS变量(childWindowHandles)甚至主页面正在刷新?
var childWindowHandles = new Array();
function redirectPage(url)
{
childWindowHandles[childWindowHandles.length] = window.open(url)
}
function confirmExit(url)
{
closeChildWindows()
window.location=url
}
function closeChildWindows()
{
for (var loop=0; loop<childWindowHandles.length; loop++)
{
if (!childWindowHandles[loop].closed)
{
childWindowHandles[loop].close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
CMS*_*CMS 10
您可以使用cookie来保存值...
编辑:您可能会发现我使用的一个简单对象:
用法:
// Store a key/value for 1 day:
cookieManager.set('name', 'a value', 1);
// Retrieve a value associated to a key:
var value = cookieManager.get('name');
// Remove a key/value:
cookieManager.remove('name');
Run Code Online (Sandbox Code Playgroud)
执行:
var cookieManager = {
set: function (name, value, expireDays) {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() + expireDays);
document.cookie = name + "=" + escape(value) +
((!expireDays) ? "" : ";expires="+expireDate.toGMTString());
},
get: function (key) {
var start,end;
if (document.cookie.length > 0) {
start = document.cookie.indexOf(key + "=");
if (start != -1) {
start = start + key.length + 1;
end = document.cookie.indexOf(";",start);
if (end == -1) {
end = document.cookie.length;
}
return unescape(document.cookie.substring(start,end));
}
}
return "";
},
remove: function (key) {
this.set(key, '', -1);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6321 次 |
| 最近记录: |