弹出窗口和关闭窗口(VB.NET/ASP.NET)

CSDN上答复一个网友的问题,CSDN限制字数,发了三个就不让我让发了hitwall.gif

Namespace Common
    Public Class Window

        <System.ComponentModel.Description("绝对关闭窗口")> _
        Public Shared Sub CloseWin()
            Dim oStringBuilder As New System.Text.StringBuilder

            oStringBuilder.Append(ControlChars.CrLf + "<script language=JavaScript>" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "<!--" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "var ua = navigator.userAgent" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "var ie = navigator.appName==""Microsoft Internet Explorer""?true:false" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "var theWin = self;" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + " " + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "while(top != theWin)" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "{" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + " theWin = top;" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "}" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + " " + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "if(ie){" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      var IEversion=parseFloat(ua.substring(ua.indexOf(""MSIE "")+5,ua.indexOf("";"",ua.indexOf(""MSIE ""))))" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      if(IEversion< 5.5){" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      var str  = '<object id=noTipClose classid=""clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"">'" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      str += '<param name=""Command"" value=""Close""></object>';" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      theWin.document.body.insertAdjacentHTML(""beforeEnd"", str);" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "      theWin.document.all.noTipClose.Click();" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "    }" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "    else{" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "       theWin.opener =null;" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "       theWin.close();" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "    }" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + " }" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "else{ " + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "       theWin.close()" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "}" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "//-->" + ControlChars.CrLf)
            oStringBuilder.Append(ControlChars.CrLf + "</SCRIPT>" + ControlChars.CrLf)

            System.Web.HttpContext.Current.Response.Write(oStringBuilder.ToString)
        End Sub

#Region "弹出窗口"

        <System.ComponentModel.Description("弹出窗口,不指定窗口位置和大小,resizable=yes")> _
        Public Shared Sub Open(ByVal sUrl As String)
            System.Web.HttpContext.Current.Response.Write("<script>" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write(" window.open('" + sUrl.Replace("'", "\'") + "');" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write("</script>" + ControlChars.CrLf)
        End Sub

        <System.ComponentModel.Description("弹出窗口,窗口屏幕居中,resizable=no")> _
        Public Shared Sub OpenWin(ByVal sUrl As String, ByVal iWidth As Integer, ByVal iHeight As Integer, Optional ByVal sWindowName As String = "")
            System.Web.HttpContext.Current.Response.Write("<script>" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write(" window.open('" + sUrl.Replace("'", "\'") + "','" + sWindowName.Replace("'", "\'") + "','scrollbars=no,resizable=no,top='+ window.screen.availHeight/2 - " + iHeight.ToString + "/2 +',left='+ window.screen.availWidth/2 - " + iWidth.ToString + "/2 +',width=" + iWidth.ToString + ",height=" + iHeight.ToString + "');" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write("</script>" + ControlChars.CrLf)
        End Sub

        <System.ComponentModel.Description("弹出窗口")> _
        Public Shared Sub Open(ByVal Url As String, ByVal NewWindowName As String, ByVal Height As Integer, ByVal Width As Integer, ByVal Top As Integer, ByVal Left As Integer, ByVal Toolbar As Boolean, ByVal Menubar As Boolean, ByVal Scrollbars As Boolean, ByVal Resizable As Boolean, ByVal Location As Boolean, ByVal Status As Boolean)
            '* 参数说明
            '* Url=page.html 弹出窗口被浏览页面的文件名
            '* NewWindowName 弹出窗口的名字(不是页面文件名) 'name',非必须,可用空''代替;
            '* height=100    窗口高度
            '* width=400     窗口宽度
            '* top=0         窗口距离屏幕上方的象素值
            '* left=0        窗口距离屏幕左侧的象素值
            '* toolbar=no    是否显示工具栏,yes为显示;
            '* menubar       是否显示菜单栏
            '* scrollbars    是否显示滚动栏。
            '* resizable=no  是否允许改变窗口大小,yes为允许;
            '* location=no   是否显示地址栏,yes为允许;
            '* status=no     是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
            '* window.open ('page.html', 'new', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no,resizable=no,location=no, status=no')
            Dim LStringBuilder As New System.Text.StringBuilder
            If IsNothing(Height) = False Then LStringBuilder.Append("height=" + Height.ToString)
            If IsNothing(Width) = False Then LStringBuilder.Append(",width=" + Width.ToString)
            If IsNothing(Top) = False Then LStringBuilder.Append(",top=" + Top.ToString)
            If IsNothing(Left) = False Then LStringBuilder.Append(",left=" + Left.ToString)
            If Toolbar Then
                LStringBuilder.Append(",toolbar=yes")
            Else
                LStringBuilder.Append(",toolbar=no")
            End If
            If Menubar Then
                LStringBuilder.Append(",menubar=yes")
            Else
                LStringBuilder.Append(",menubar=no")
            End If
            If Scrollbars Then
                LStringBuilder.Append(",scrollbars=yes")
            Else
                LStringBuilder.Append(",scrollbars=no")
            End If
            If Resizable Then
                LStringBuilder.Append(",resizable=yes")
            Else
                LStringBuilder.Append(",resizable=no")
            End If
            If Location Then
                LStringBuilder.Append(",location=yes")
            Else
                LStringBuilder.Append(",location=no")
            End If
            If Status Then
                LStringBuilder.Append(",status=yes")
            Else
                LStringBuilder.Append(",status=no")
            End If

            System.Web.HttpContext.Current.Response.Write("<script>" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write("window.open('" + Url.Replace("'", "\'") + "','" + NewWindowName.Replace("'", "\'") + "','" + LStringBuilder.ToString + "');" + ControlChars.CrLf)
            System.Web.HttpContext.Current.Response.Write("</script>" + ControlChars.CrLf)
        End Sub
#End Region

    End Class

End Namespace

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值