Recently, the project used the. NET Server control again!
It is found that the showmodaldialog method in Chrome does not display a modal dialog box. Just like opening a page, the parent window can still obtain the focus at will and open multiple forms, in addition, the returned returnvalue cannot be returned, which is always undefined. So many problems are a headache. Next we will test the latest mainstream browsers.
Browser |
Supported? |
Status |
Ie9 |
○ |
|
Firefoxbench |
○ |
|
Safari5.1 |
○ |
|
Chrome19.0 |
× |
A new form is opened instead of a modal dialog box. |
Opera12.0 |
× |
Nothing happens, not even a form |
What is chrome open?
Because the opening is not a modal dialog box, but like opening a new form, you only need to verify whether window. opener is empty.
<SCRIPT type = "text/JavaScript">Alert (window. opener );</SCRIPT>
In Chrome, a [Object window] object is displayed, While IE is undefined. Now chrome treats showmodaldialog as window. Open. That is to say, we can use window. opener to operate the subforms in chrome. Here we also found a very interesting phenomenon. In Firefox, we tested window. opener is not empty, so I tested the window in the subform using showmodaldialog. opener and window. dialogarguments in various browsers, becauseThe operabrowser does not even play a form. In the following test, it will be removed.
Description A in the showmodaldialog method of the parent formRguments is passed as a window object. The test result is as follows:
browser |
Modal Dialog Box |
window. Opener |
window. dialogarguments |
returnvalue |
ie9 |
○ |
undefined |
[Object window] |
○ |
firefoxlogs |
○ |
[Object window] |
[Object window] |
○ |
safari5.1 |
○ |
[Object window] |
[Object window] |
○ |
chrome19.0 |
× |
[Object window] |
undefined |
× |
The above is the result of my test. The degree of support varies with browsers. Also, in the Firefox browser, if the Sub-form is refreshedWindow. dialogarguments will still be lost and become undefined. In the above results, we can see that the returned value of returnvalue is undefined only returned by Chrome, and no problem exists in other browsers. How can we solve this problem?
Solve the returnvalue Problem
Through the above tests, we know that Chrome's showmodaldialog method is much like executing the window. Open method, so we can use window. opener to implement the window. returnvalue function.
Note: The random parameter temp = math. Random () is used to solve the cache problem. Many friends have tested undefined because it is a cache problem.Append
JS of the parent formCode:
Window. onload =Function(){VaRReturnvalue = Window. showmodaldialog ("son.html? Temp = "+Math. Random (), window );//For chromeIf(Returnvalue =Undefined) {returnvalue=Window. returnvalue;} alert (returnvalue );}
JS Code of the subform part:
If(Window. opener! =Undefined ){//For chromeWindow. opener. returnvalue = "opener returnvalue";}Else{Window. returnvalue= "Window returnvalue";} Window. Close ();
This can also be used in IE, Firefox, chrome, Safari, and other browsers.