JS in ShowModalDialog detailed use

Source: Internet
Author: User

(Transferred from: http://www.cnblogs.com/Dlonghow/archive/2009/06/04/1496141.html)

Basic Introduction:
ShowModalDialog () (IE 4+ support)
showModelessDialog () (IE 5+ support)
The window.showModalDialog () method is used to create a modal dialog box that displays HTML content.
The Window.showmodelessdialog () method is used to create a non-modal dialog box that displays HTML content.
How to use:
Vreturnvalue = window.showModalDialog (sURL [, varguments] [, Sfeatures])
Vreturnvalue = Window.showmodelessdialog (sURL [, varguments] [, Sfeatures])
Parameter description:
sURL--Required parameter, type: String. Used to specify the URL of the document to be displayed by the dialog box.
Varguments--optional parameter, type: Variant. Used to pass parameters to the dialog box. There are no limits on the types of arguments passed, including arrays. dialog box through 

Window.dialogarguments to get the arguments passed in.
Sfeatures--optional parameter, type: String. Used to describe the appearance of the dialog box and other information, you can use the following one or several, with a semicolon ";" Separated.
----------------
1. Dialogheight: Height of dialog box, not less than 100px
2. Dialogwidth: Width of the dialog box.
3. Dialogleft: Distance from the left of the screen.
4. Dialogtop: Distance from the screen.
5. Center: {yes | no | 1 | 0}: Center, default yes, but can still specify height and width.
6. Help: {yes | no | 1 | 0}: Whether to display the Assist button, default yes.
7. Resizable: {yes | no | 1 | 0} [ie5+]: Whether the size can be changed. Default No.
8. Status: {yes | no | 1 | 0} [ie5+]: Whether the status bar is displayed. Default is yes[Modeless] or no[modal].
9. Scroll: {yes | no | 1 | 0 | on | off}: Scroll bar is displayed. The default is yes.

The following properties are used in an HTA and are generally not used in general Web pages.
dialoghide:{Yes | no | 1 | 0 | on | off}:Printor whether the dialog box is hidden when you print the preview. The default is No.
edge:{Sunken | raised}: Indicates the border style of the dialog box. The default is raised.
unadorned:{Yes | no | 1 | 0 | on | off}: default is No.

parameter passing:
1. To pass a parameter to a dialog box, pass it through varguments. Type is not limited, for string types, the maximum is 4,096 characters. You can also pass objects, for example:
-------------------------------
Parent.htm
<script>
var obj = new Object ();
Obj.name= "51js";
window.showModalDialog ("modal.htm", obj, "dialogwidth=200px;dialogheight=100px");
</script>
Modal.htm
<script>
var obj = window.dialogarguments
Alert ("You passed the parameter:" + obj.name)
</script>
-------------------------------
2. You can return information by Window.returnvalue to the window that opens the dialog box, or it can be an object. For example:
------------------------------
Parent.htm
<script>
Str =window.showmodaldialog ("modal.htm",, "dialogwidth=200px;dialogheight=100px");
alert (str);
</script>
Modal.htm
<script>
Window.returnvalue= "http://homepage.yesky.com";
</script>

Common tips:

First, how to let the ShowModalDialog and showModelessDialog hyperlinks do not pop up a new window?
Add <base target= "_self" > on the page that is opened. This sentence is usually placed between

Second, how to refresh the contents of ShowModalDialog and showModelessDialog?
In ShowModalDialog and showModelessDialog can not press F5 refresh, and can not pop-up menu. This only depends on

JavaScript, here is the relevant code:

<body onkeydown= "if (event.keycode==116) {Reload.click ()}" >
<a id= "Reload" href= "filename.htm" style= "Display:none" >reload...</a>

Replace the filename.htm with the name of the Web page and put it in your open Web page, press F5 to refresh, note that this is to

With <base target= "_self" > Use, otherwise you press F5 will pop up a new window.

Third, how to use JavaScript to turn off ShowModalDialog (or showmodelessdialog) open windows.
<input type= "button" value= "Close" onclick= "Window.close ()" >
Also to cooperate with <base target= "_self", otherwise it will open a new IE window, and then turn it off.

Iv. Math.random and ShowModalDialog.

When you set the pop-up page fixed (such as the "modal.htm" page above), IE is likely to the temporary file area, download the last generated page (openpage.html), without reloading,

For dynamically loaded pages, this often produces misunderstandings, such as not updating the data in a timely manner, it is even more detrimental to the developer testing. So, you can use the following methods:

var strpage = "/medal.htm?random=" +math.random ();

So every time the strpage is not the same, the reason is not self-evident.

JS in ShowModalDialog detailed use

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.