0

我有一个 Java 项目,使用 Java 脚本来管理站点。我有一个打开帮助对话框弹出窗口的功能。当我刷新主页时,弹出窗口没有关闭,它仍然打开。我有一个保护,您可以在帮助下打开 2 个窗口,但它正在使用处理程序 (helpWnd),在刷新主页时它会丢失。

对不起我的英语不好; )

var helpWnd = null;
// Open help dialog with url from recived helpId
function openHelpDialog(helpId, height, width, title) {
    var url;
    if(helpId == "contact") {
        url = "help/contact.html";
    } else {
        var regularExpression = /[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9]/;
        if(helpWnd!=null) {
            helpWnd.close();
        }
        url = "help/index.html?"+helpId.toLowerCase()+".html";
        if(!regularExpression.test(helpId)) {
            url = "help/index.html";
        }
    }
    helpWnd = window.open(url, title, 'width=1000, height=600, menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no');
}

//this refresh main page
function changeRole(roleName,redirectUrl) {
    dojo.xhrPost({
        content: {
            role: roleName 
        },
        handleAs: "json",
        sync: true,
        url: 'someUrl.npi',
        load: function (response) {
            dojo.cookie(response.cookieHash, response.role, {expires : response.cookieExpiryTime});
            document.location.href = redirectUrl;
        }
    });
}
4

1 回答 1

0

正如您可能已经发现的那样,在许多情况下打开窗户被认为是有害的。

更好的选择是使用带有 javascript 的模态对话框,它本质上是同一页面中的分层对话框。我不是 Dojo 专家,但我很快找到了 Google 的文档 (http://dojotoolkit.org/reference-guide/1.7/dijit/Dialog.html)

无论如何,如果你仍然想去打开窗户,如果你确保它得到关注,你可能会得到更好的行为。看看这里:http ://www.quirksmode.org/js/popup.html

于 2012-04-18T09:31:47.160 回答