Jsp js pop-up webpage dialog box

Source: Internet
Author: User
DHTML can be used in two ways:

1. Use the window. Open Method to bring up the page. 2. Use the window. showmodaldialog method to bring up a dialog box. (Recommended) 1. The window. Open dialog box is displayed.When writing a JSP page, you sometimes need to click a button to bring up an input dialog box, enter a value, and then close the dialog box, write data to the database, and refresh the current page. This function can be implemented using JavaScript. However, if you use a self-contained JS dialog box, the dialog box is not beautiful. Instead, you can use a JSP page to create a dialog box. In the addname. to call the dialog box in JSP, write a JSP page newbox. JSP (used as a dialog box), and then on the page addname. add a piece of JS Code in JSP:/* used to open the dialog box page */function OpenWindow (){
Window. open ("newbox. JSP "," sample "," fullscreen = No, toolbar = No, location = No, directories = No, status = No, menubar = No, scrollbars = No, resizable = No, copyhistory = No, width = 350, Height = 140, Left = 200, Top = 300 ");
}/* Call this function in newbox. jsp to refresh addname. jsp */function opensub (){
Document. form1.submit ();
} Here we want to describe the parameters in window. Open: fullscreen = no window mode, yes is full screen mode toolbar = No, display Toolbar
Location = No. The URL bar is displayed.
Directories = No, navigation bar
Status = No, Status Bar
Menubar = No, menu
Scrollbars = No, scroll bar
Resizable = No, whether the size can be changed
Copyhistory = No, history button
Width = 350, width
Height = 140 'High
Left = 200, 200 from left
Top = 300, 300 away from the top. Add some JS Code to newbox. jsp. The following is the code of newbox. jsp.
<HTML>
<Head>
<Title> Create a folder input box </title>
<SCRIPT>
<! --
Function bconfirm (){
Opener.doc ument. All ['inboxname']. value = Document. form1.inboxname. value;
Opener. opensub ();
Window. Close ();
}

Function bcancel (){
Window. Close ();
}
-->
</SCRIPT>
</Head>

<Body bgcolor = #66cd00>
<Font size = 5> enter the name of the new Folder: </font>
<Form method = post name = form1 action = "">
<Input type = text name = inboxname size = 35> <p>
<Input type = button name = inputboxbt value = confirm onclick = "bconfirm ();">
<Input type = button name = inputboxbs value = Cancel onclick = "bcancel ();">
</Form>

</Body>
</Html>
In newbox. addname in JSP first. an inboxname value for a hidden form in JSP is: opener.doc ument. all ['inboxname']. value = document. form1.inboxname. value, and then call addname. a js function in JSP: opener. opensub (); addname. JSP will automatically submit the form to the servlet and then refresh the page. This is done!

2. The window. showmodaldialog dialog box is displayed. (Recommended)
Still on the page addname. to call the dialog box in JSP, write a JSP page newbox. JSP (used as a dialog box), and then on the page addname. add a JS Code in JSP:/* to open the dialog box page. Note that the method in the OpenWindow () function is window. showmodaldialog */function OpenWindow (){
Window. showmodaldialog ("newbox. jsp", window, "status: No; scroll: No;
Dialogwidth: 235px; dialogheight: 100px ");
}/* Call this function in newbox. jsp to refresh addname. jsp */function opensub (){
Document. form1.submit ();
}

The parameters in window. showmodaldialog are described as follows: Center: Yes | no | 1 | 0 | on | off indicates whether the dialog box is displayed in the center of the desktop. The default value is yes.
Dialoghide: Yes | no | 1 | 0 | on | off specifies whether the dialog box is hidden when printing or previewing. This parameter is only available when the dialog box is opened by a trusted program. The default value is no.
Edge: sunken | raised specifies whether the border style of the dialog box is concave or convex. The default value is raised.
Resizable: Yes | no | 1 | 0 | on | off specifies whether the dialog box can be changed by the user. The default value is no.
Scroll: Yes | no | 1 | 0 | on | off specifies whether a scroll bar is displayed in the dialog box. The default value is yes.
Status: Yes | no | 1 | 0 | on | off specifies whether the dialog box shows status bars. The default value of the untrusted dialog box is yes. The default value of the trusted dialog box is no.
Unadorned: Yes | no | 1 | 0 | on | off specifies whether the chrome style border is displayed in the dialog box. This parameter is only available when the dialog box is opened by a trusted program. The default value is no.

In addition, in the newbox. jsp JavaScript code bconfirm () method:
<SCRIPT>
<! --
Function bconfirm (){
Dialogarguments. Addnameform. inboxname. value = Document. form1.
Inboxname. value;
Dialogarguments. Opensub ();
Window. Close ();
}
Function bcancel (){
Window. Close ();
}
-->
</SCRIPT>

Note: addnameform is used to hide the form name in addname. jsp. The window. showmodaldialog method is used to pass Parameters Using dialogarguments. Other parts remain unchanged.

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.