快顯視窗和關閉視窗(VB.NET/ASP.NET)

來源:互聯網
上載者:User

在CSDN上回覆一個網友的問題,CSDN限制字數,發了三個就不讓我讓發了

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.