showModalDialog and showModelessDialog_javascript tricks
WBOYOriginal
2016-05-16 19:20:20843browse
Regarding the use of showModalDialog and showModelessDialog, the window that pops up using window.open in a b/s structure project is blocked by some advertising blocking tools. There is no other way but to use showModalDialog to solve the problem, but the disadvantage of showModalDialog is that It's too troublesome to pass values between pages (there are two ways to pass values), but there is really no other way to solve this interception problem, the only way is to use this. The code was written in just two strokes, but a problem was discovered when debugging the code. The content in the window that popped up using showModalDialog was always the content displayed when the page was accessed for the first time. From the beginning, I suspected that it was the page cache called by the form. Finally, single-step tracking and debugging also proved that the problem is indeed the read page cache. This shows that when using showModalDialog and showModelessDialog to make pop-up forms in asp.net, it is best to add Response.Expires = 0; Response.Cache.SetNoStore(); Response.AppendHeader("Pragma", "no-cache"); to clear the cache. Use asp, php, js, vbscript to test the showModalDialog method and there is no need to clear the cache. You can use it with confidence. Regarding showModalDialog, you can refer to the detailed introduction I found below
Usage experience of showModalDialog and showModelessDialog
1. What is the difference between showModalDialog and showModelessDialog? ShowModalDialog: After being opened, the input focus will always be maintained. The user cannot switch to the main window unless the dialog box is closed. Similar to the operation effect of alert. ShowModelessDialog: After being opened, the user can randomly switch the input focus. It has no effect on the main window (at most it is blocked for a while. :P)
2. How to prevent the hyperlinks in showModalDialog and showModelessDialog from popping up new windows? Just add to the opened web page. This sentence is usually placed between and
.
3. How to refresh the content in showModalDialog and showModelessDialog? In showModalDialog and showModelessDialog, you cannot press F5 to refresh, and the menu cannot pop up. This can only rely on javascript. The following is the relevant code:
Replace filename.htm with the name of the web page and then Put it into the webpage you open and press F5 to refresh. Note that this must be used in conjunction with , otherwise a new window will pop up when you press F5.
Note: If you want to refresh automatically when accessed, you can set a record variable on the opened page. When the modal window is opened, set the variable to 1, and then use the above method to refresh the modal window. , when the window is closed, the variable reaches 0.
4. How to use javascript to close the window opened by showModalDialog (or showModelessDialog).
Also cooperate with , otherwise a new IE window will open and then be closed.
5. Data transfer skills of showModalDialog and showModelessDialog. Example: Now you need to read or set a variable var_name in a showModalDialog (or showModelessDialog)
General delivery method: window.showModalDialog("filename.htm",var_name ) ] forwardover over in] when read and set in showModalDialog (or showModelessDialog]: alert(window.dialogArguments)////Read var_name variable Window.dialogArguments="oyiboy"/ /Set var_name variable This method is satisfactory, but what if you want to operate var_name and then operate the second variable var_id at the same time? It can no longer be operated. This is the limitation of this delivery method.
The following is the delivery method I recommend: window.showModalDialog("filename.htm",window) ///No matter what variables you want to operate, only pass the window object of the main window directly When reading and setting showModalDialog (or showModelessDialog): alert(window.dialogArguments.var_name) //Read the var_name variable window.dialogArguments.var_name="oyiboy" //Set the var_name variable
At the same time, I can also operate the var_id variable > You can also operate on any object in the main window, such as elements in the form object. window.dialogArguments.form1.index1.value="This is setting the value of the index1 element"
6. Interoperation of multiple showModelessDialog.
The main function of the following code is to move the position of another showModelessDialog within a showModelessDialog.
Part of the js code of the main file. var s1=showModelessDialog('control.htm',window,"dialogTop:1px;dialogLeft:1px") //Open the control window var s2=showModelessDialog('about:blank',window,"dialogTop: 200px;dialogLeft:300px") //Open the controlled window
This example is just the difference between showModelessDialog and showModelessDialog Through the position operation function between showModelessDialog, through this principle, the respective display pages can be controlled between showModelessDialog, variables and data can be transferred, etc. This depends on your performance.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn