小弟是做网上银行的,以前的系统适用于IE,现想将适用的浏览器扩大到firefox.但是遇到了js的兼容性问题。
在personalBank.jsp中有这样一段代码检测多窗口问题
<script>
 if (window.opener==null) {
        
        if (window.parent.security.encAppletId != '<%=session.getAttribute("Encryption.encAppletId")%>') {
     window.location = '<%=request.getContextPath()%>/jsp/chs/personal/errorMultiWindow.jsp';
}
} else {
<% String ignoreCheck = (String) request.getAttribute("ignoreCheckMultiWindow");
if ((ignoreCheck == null) || (ignoreCheck.equalsIgnoreCase("N"))) {
%>              
             if (opener.name.indexOf('chs_main') == 0&&navigator.userAgent.indexOf('Firefox')<0) {
window.location = '<%=request.getContextPath()%>/jsp/chs/personal/errorMultiWindow.jsp';
}
<%}%>
}
</script>
所有页面均使用struts的template框架,当我使用系统中的链接去打开其他页面时(未用window.open,而且target是自己本身)。在IE中获取到的window.opener是
undefine的,window.parent是个object.但在firefox却很奇怪,window.opener和window.parent都是个object.所以使用所有链接时都会跑到else的statment中去。请问各位大虾,在firefox中用没有其他的方法可以识别是不是用了window.open新开了一个窗口(检查当前窗口是否有父窗口)。

解决方案 »

  1.   


    <a href="a.htm" target="_blank">w1</a><br />
    <a href="#" onclick="javascript:window.open('a.htm');">w2</a><script language="JavaScript">var OpenedWins = [];
    window.open2 = window.open;
    window.open = function(u)
    {
    OpenedWins.push(window.open2(u));
    }if (window.opener && window.opener.OpenedWins)
    for (var i in window.opener.OpenedWins)
    if (window.opener.OpenedWins[i] == this)
    {
    alert("opened by window.open()");
    break;
    }
    </script>
    靠window属性实在判断不出来,只好这样...