A perfect solution to the problem of return value compatibility in JS modal window _javascript tips

Source: Internet
Author: User

Because the system should be compatible with the original IE has been used to close the method, measured by debugging, it is necessary to window.dialogarguments more than the test, otherwise easy to problem.

function Okend (vals) {
  if (Vals = null) Vals = "TRUE";
  if (typeof (Window.opener) = = "undefined") {
    if (typeof (Window.dialogarguments)!= "undefined") {
      if (window.dia logarguments && window.dialogarguments!= null) {
        window.opener = window.dialogarguments;
        if (window.opener && window.opener!= null) {
          window.opener.ReturnValue = vals;
        }
      }
    }
  }
  else {
    if (window.opener && window.opener!= null) {
      window.opener.ReturnValue = Vals;
    }
  }
  Window.returnvalue = Vals;
  Self.close ();
}

Return value received, only in the original IE received mode, more than a Test opener on it, as follows:

Select Change Department
     function SetOrganizeTree2 () {var url= "pop-up page";
       var ret = window.showmodaldialog (URL, window, "Dialogwidth=400px;dialogheight=500px;status=no;help=no;scroll=yes"; Resizable=yes; ");
       if (typeof (ret) = = "undefined") {
         ret = window. returnvalue;
       }
       if (ret) {
         document.getElementById ("HidDeptCode2"). Value = RET;
         document.getElementById ("Btndeptcodeadd"). Click ();
       return false;
     }

JS modal window return value compatibility problem perfect solution

1. When the pop-up window is opened, the window is passed as the second parameter.

 var result = window.showModalDialog (URL, window, "dialogwidth=" + width + "px;dialogheight=" + height + "Px;resizable:yes; ")

 if (typeof (Result) = = ' undefined ') {result

     = window. returnvalue;

   }

   return result;

2, in the pop-up window, execute the following JS to receive the incoming window

 if (typeof (Window.opener) = = ' undefined ') Window.opener = window.dialogarguments;

3, the pop-up window before closing, call the following JS assignment return value

 Window.returevalue = Vals;

    if (window.opener && window.opener!= null)

        window.opener.ReturnValue = Vals;

 

    Window.close ();

Principle discussion:

Chrome, the standard method, when the pop-up page does not postback, can return a value. A postback is not a normal return value. This method can be resolved.

IE standard method, sometimes unknown reason can not return the value correctly, this method can be resolved.

FF not tested in detail, should not be a problem.

The above JS modal window return value compatibility problem of the perfect solution is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

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.