showModalDialog()

Detailed use of showModalDialog in JS (transfer)

basic introduction:

   showModalDialog()         (IE 4+ 支持)           

   showModelessDialog()      (IE 5+ 支持)           

   window.showModalDialog()                  方法用来创建一个显示HTML内容的模态对话框。         

   window.showModelessDialog()             方法用来创建一个显示HTML内容的非模态对话框。 

Instructions:

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 in the dialog box.

vArguments-optional parameters, type: variant. Used to pass parameters to the dialog box. The type of parameters passed is not limited, including arrays, etc.

The dialog box obtains the passed parameters through window.dialogArguments.

sFeatures-optional parameters, type: string. Used to describe the appearance of the dialog box and other information, you can use one or more of the following, separated by a semicolon ";". ----------------

  1. dialogHeight: dialog height, not less than 100px

  2. dialogWidth: The width of the dialog box.

  3. dialogLeft: The distance from the left of the screen.

  4. dialogTop: The distance from the screen.

  5. center: {yes | no | 1 | 0}: Whether to center or not, the default is yes, but the height and width can still be specified.

  6. help: {yes | no | 1 | 0 }: Whether to display the help button, the default is yes.

  7. resizable: {yes | no | 1 | 0} [IE5+]: Whether it can be resized. The default is no.

  8. status: {yes | no | 1 | 0} [IE5+]: Whether to display the status bar. The default is yes[Modeless] or no[Modal].

  9. scroll: {yes | no | 1 | 0 | on | off }: Whether to display the scroll bar. The default is yes.
    The following attributes are used in HTA, and are generally not used in general web pages.

  10. dialogHide: {yes | no | 1 | 0 | on | off }: Whether the dialog box is hidden during printing or print preview. The default is no.

  11. edge:{ sunken | raised }: Specify the border style of the dialog box. The default is raised.

  12. unadorned: {yes | no | 1 | 0 | on | off }: The default is no.
    Parameter passing: 1. To pass parameters to the dialog box, pass through vArguments. There is no restriction on the type. For the string type, the maximum is 4096 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("您传递的参数为:" + obj.name)

 </script>

2. You can return information to the window that opened the dialog box through window.returnValue, and of course it can also be an object. E.g: ------------------------------

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 skills:

1. How to prevent the hyperlinks in showModalDialog and showModelessDialog from popping up new windows? Just add it to the opened webpage. This sentence is generally placed in between.

2. How to refresh the content in showModalDialog and showModelessDialog? In showModalDialog and showModelessDialog, you can't press F5 to refresh, and you can't pop up the menu. This can only rely on

javascript, the following is the relevant code:

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

Replace filename.htm with the name of the webpage and put it in the webpage you opened, press F5 to refresh it. Note that this must

Use with it, otherwise a new window will pop up when you press F5.

3. How to use javascript to close the window opened by showModalDialog (or showModelessDialog). Also cooperate, otherwise it will open a new IE window and then close it again.

Fourth, Math.random and showModalDialog.

When the pop-up page you set is fixed (such as the "modal.htm" page above), ie, it is very likely to go to the temporary file area and download the page (openPage.html) generated last time without reloading.

For dynamically loaded pages, this often leads to misunderstandings. If the data is not updated in time, it is even more unfavorable for developers to test. Therefore, you can use the following methods:

var strPage = “/medal.htm?random="+Math.random();

In this way, the strPage generated each time is different, and the reason is self-explanatory.

Guess you like

Origin blog.csdn.net/yunxiang1224/article/details/88350420