Convenient JavaScript class

Source: Internet
Author: User

Public class Javascript
{
Public JavaScript ()
{
//
// Todo: add the constructor logic here
//
}
/// <Summary>
/// The pop-up message box is displayed.
/// </Summary>
/// <Param name = "message"> message </param>
Public static void alert (string message)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("alert ('");
Javastr. append (message. Replace ("'",""));
Javastr. append ("');");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Page Jump
/// </Summary>
/// <Param name = "url"> jump address </param>
Public static void redirect (string URL)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("window. Location. href = '");
Javastr. append (URL. Replace ("'",""));
Javastr. append ("';");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Custom call
/// </Summary>
/// <Param name = "funname"> method name. Other statements can be written directly. </param>
Public static void run (string funname)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append (funname + ";");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Page pop-up mode window
/// </Summary>
/// <Param name = "url"> </param>
/// <Param name = "widt"> </param>
/// <Param name = "height"> </param>
Public static void showdialogarg (string URL, string width, string height)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("Var sfeature = dialogwidth:" + width + "PX; dialogheight:" + height + "PX; resizable: No; scroll: No; center: Yes; help: No; ");
Javastr. append ("return window. showmodaldialog (URL, window, sfeature );");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Page pop-up message, close
/// </Summary>
/// <Param name = "message"> message </param>
/// <Param name = "url"> page to jump to </param>
Public static void alertgo (string message, string URL)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("alert ('");
Javastr. append (Message );
Javastr. append ("');");
Javastr. append ("window. Location. href = '");
Javastr. append (URL );
Javastr. append ("';");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Page pop-up message, close
/// </Summary>
/// <Param name = "message"> message </param>
/// <Param name = "url"> page to jump to </param>
Public static void alertgo (string message, string URL, string flag)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("alert ('");
Javastr. append (Message );
Javastr. append ("'); If (window. Parent = NULL )");
Javastr. append ("window. Location. href = '");
Javastr. append (URL );
Javastr. append ("'; else window. Parent. Location. href = '");
Javastr. append (URL );
Javastr. append ("';");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

 

///


// The message is displayed on the page, close the current window
///
/// message
Public static void alertclosepage (string message)
{< br> stringbuilder javastr = new stringbuilder ();
javastr. append ("");
system. web. httpcontext. current. response. write (javastr. tostring ();
}

///


// a message is displayed on the page. Close the current window and refresh the parent window. Note: The current window must be a window. open page)
///
/// message
Public static void alertclosepagerefopener (string message)
{< br> stringbuilder javastr = new stringbuilder ();
javastr. append ("");
system. web. httpcontext. current. response. write (javastr. tostring ();
}

///


// close the page
///
Public static void closepage ()
{< br> stringbuilder javastr = new stringbuilder ();
javastr. append ("");
system. web. httpcontext. current. response. write (javastr. tostring ();
}

/// <Summary>
/// Open a new window
/// </Summary>
/// <Param name = "url"> URL of the new window </param>
Public static void open (string URL)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("window. Open ('");
Javastr. append (URL );

Javastr. append ("');");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Open a new window
/// </Summary>
/// <Param name = "url"> URL of the new window </param>
/// <Param name = "width"> width of the new window </param>
/// <Param name = "height"> height of the new window (the height should not exceed 730) </param>
Public static void open (string URL, int width, int height)
{
Stringbuilder javastr = new stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("Var width =" + width. tostring () + ";");
Javastr. append ("Var Height =" + height. tostring () + ";");
Javastr. append ("Var Sw = screen. width ;");
Javastr. append ("Var SH = screen. height ;");
Javastr. append ("Var left = (SW-width)/2 ;");
Javastr. append ("Var Top = (Sh-height)/2 ;");

Javastr. append ("window. Open ('");
Javastr. append (URL );
Javastr. append ("',' _ blank ',");
Javastr. append ("'rollbars = Yes, Top =" + "'+ TOP +'" + ", Left =" + "'+ Left +'" + ", resizable = No, status = No, toolbar = No, menubar = No, location = No, width = "+" '+ width +' "+ ", height = "+" '+ height + '");

Javastr. append ("');");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());

}
/// <Summary>
/// Close the page and refresh the parent page. (Note: The page must be opened with window. open)
/// </Summary>
Public static void closeandrefopener ()
{
System. Text. stringbuilder javastr = new system. Text. stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("window. opener. Location. href = Window. opener. Location. href ;");
Javastr. append ("window. Opener = NULL ;");
Javastr. append ("self. Close ();");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}

/// <Summary>
/// Close the page, PASS Parameters to the parent page, and refresh the parent page. (Note: The page must be opened with window. open)
/// </Summary>
/// <Param name = "values"> parameter value passed to the parent page. </Param>
/// <Param name = "valuename"> parameter name passed to the parent page </param>
Public static void closeandrefopener (string valuename, string values)
{
System. Text. stringbuilder javastr = new system. Text. stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("Var url = Window. opener. Location. href ;");
Javastr. append ("Var I = URL. indexof ('? ');");
Javastr. append ("if (I! =-1 ){");
Javastr. append ("url = URL. substring (0, I );");
Javastr. append ("}");
Javastr. append ("window. opener. Location. href = URL + '? "+ Valuename. Trim () +" = '+' "+ values + "';");
Javastr. append ("window. Opener = NULL ;");
Javastr. append ("self. Close ();");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}
/// <Summary>
/// Close the page and submit the form of the parent page. (Note: The page must be opened with window. open)
/// </Summary>
/// <Param name = "formname"> from name of the parent page </param>
Public static void closeandrefopener (string formname)
{
System. Text. stringbuilder javastr = new system. Text. stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("window. opener." + formname. Trim () + ". Submit ();");
Javastr. append ("window. Opener = NULL ;");
Javastr. append ("self. Close ();");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());


}

/// <Summary>
/// Close the page and click a button on the parent page. (Note: The page must be opened with window. open)
/// </Summary>
/// <Param name = "formname"> button name </param>
Public static void closeandpostopenerbutton (string buttonname)
{
System. Text. stringbuilder javastr = new system. Text. stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("using your opener.doc ument. getelementbyid ('" + buttonname. Trim () + "'). Click ();");
Javastr. append ("window. Opener = NULL ;");
Javastr. append ("self. Close ();");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());


}

/// <Summary>
/// The current page jumps out of the framework and jumps to the specified page
/// </Summary>
/// <Param name = "url"> URL of the new page </param>
Public static void leapiframetonewurl (string URL)
{
System. Text. stringbuilder javastr = new system. Text. stringbuilder ();
Javastr. append ("<script language = JavaScript> ");
Javastr. append ("Var parentwin = Window. parent ;");
Javastr. append ("If (parentwin = NULL ){");
Javastr. append ("window. Location. href = '" + URL + "';}");
Javastr. append ("else {parentwin. Location. href = '" + URL + "';}");
Javastr. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (javastr. tostring ());
}


}

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.