Pop-up and close windows (VB. NET/ASP. NET)

Source: Internet
Author: User

Reply to a netizen's question on csdn. The number of characters in csdn is limited. If three words are sent, I will not be allowed to send them.

Namespace common
Public class window

<System. componentmodel. Description ("Close Window absolutely")> _
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.doc ument. Body. insertadjacenthtml (" "beforeend" ", STR);" + controlchars. CRLF)
Ostringbuilder. append (controlchars. CRLF + "thewin.doc ument. 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 "pop-up window"

<System. componentmodel. Description ("the window does not specify the position and size, 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 ("window displayed, center window, 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 ("pop-up window")> _
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)
'* Parameter description
'* URL page.html: the file name of the browsed page in the pop-up window.
'* Newwindowname: the name of the pop-up window (not the Page name) 'name'. It is optional and can be replaced by null;
'* Height = 100 window height
'* Width = 400 window width
'* Top = 0 pixels between the window and the top of the screen
'* Left = 0 pixel value from the left side of the screen
'* Toolbar = No indicates whether to display the toolbar. Yes indicates whether to display the toolbar;
'* Does menubar display the menu bar?
'* Indicates whether the scrollbars displays a scroll bar.
'* Resizable = No indicates whether to change the window size. Yes indicates yes;
'* Location = No indicates whether the address bar is displayed. Yes indicates yes;
'* Status = No indicates whether the information in the status bar is displayed (usually the file has been opened). Yes indicates 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.