0

弹出窗口用于允许用户在单独的窗口中打开文档页面。当用户试图打开下一个文档页面时,必须关闭所有以前的文档页面窗口。

所以基本上,我想关闭多个弹出窗口。为了保存打开的弹出窗口的引用,我将包含弹出窗口引用的数组保存在一个变量中,并且该变量的值保存在一个隐藏字段中。

现在,popup = window.open('', '', sOptions);返回[object],当它[object]被检索到时,它会生成一个错误,即对象不支持这个属性或方法。

我在使用 asp/vb.net 开发的 Web 应用程序中使用以下 javascript:

    var popupWin = new Array();

    function OnPopupClick(url,title,name) {
        var popup = null;
        var sOptions;
        sOptions = 'status=yes,menubar=no,scrollbars=yes,resizable=yes,toolbar=no,titlebar=yes,location=0,directories=0';
        sOptions = sOptions + ',width=' + (screen.availWidth - screen.availWidth / 2).toString();
        sOptions = sOptions + ',height=' + (screen.availHeight - 50).toString();
        sOptions = sOptions + ',screenX=0,screenY=0'
        sOptions = sOptions + ',left=' + ((screen.availWidth / 2) - 10).toString();
        sOptions = sOptions + ',top=0';
        html = '<html><head><title>'+ title + '</title></head><body style="margin: 0px 0; text-align:center; "><IMG src="' + url + '" BORDER=0 NAME=image height="' + (screen.availHeight - 50).toString() +'" width="' + ((screen.availWidth - screen.availWidth / 2)-20).toString() +'" onload="window.resizeTo((document.image.width-(document.image.width-(screen.availWidth - screen.availWidth / 2)))+10,((document.image.height*1.3)-(screen.availHeight - 50))+((screen.availHeight - 50)*3)";></body></html>';
        popup = window.open('', '', sOptions);
        popup.document.open();
        popup.document.write(html);
        popup.document.focus();
        popup.document.close();

        if(document.getElementById('<%= hidTitle.ClientID %>').value!=name){
            ClosePopupWin(document.getElementById('<%= hidWinRef.ClientID %>').value);
        }
        TrackPopupWinOpen(popup,name); 
   }

    function TrackPopupWinOpen(winName,title) {
        popupWin[popupWin.length] = winName;
        var index = popupWin.length-1;
        var val = popupWin.join();

        document.getElementById('<%= hidWinRef.ClientID %>').value=val;
        document.getElementById('<%= hidTitle.ClientID %>').value=title;
    }

    function ClosePopupWin(retVal) {
        popupWin[popupWin.length]=retVal.split();
        var openCount = popupWin.length;
        for (i = 0; i < openCount; i++) {
            popupWin[i].close();
        }
    }

我究竟做错了什么?

我不能使用任何第三方工具。我只能使用asp中可用的控件。

4

1 回答 1

0

我建议使用不同的方法。弹出窗口会带来超出您所描述的各种问题,主要是广告拦截软件。即便如此,还有一种更有效的方法可以做到这一点。使用扩展或浮动 div 来管理这些。根据您发布的 Javascript,没有异步检索任何数据,因此不需要弹出窗口。如果您只是使用函数或 .NET 控件在页面底部的 div 中呈现图像,则可以使用 CSS 和更轻量级的 Javascript 使用绝对(或固定)定位来打开和关闭这些图像。

于 2012-09-30T09:02:56.830 回答