Google Chrome no longer supports ShowModalDialog's solution

Source: Internet
Author: User

Problem recurrence

Pop-up window encoding:

JavaScript
01234567 var obj = new Object(); var retval = window. ShowModalDialog("request.aspx",obj,"dialogwidth=500px;dialogheight=300px") ;if (retval = = null) { . . .}Else { . . .}

Browser Exceptions:

Shell
01 uncaught TypeError: Undefined is not a function

If this is the exception, unfortunately you are already lying on the gun. This question can be seen here:

Http://windowsitpro.com/blog/google-kills-showmodaldialog-api-chrome-37-and-does-evil-exchange-owa

Http://www.infoq.com/news/2014/09/chrome-showmodaldialog

Some of these temporary solutions, but it seems ShowModalDialog will not return.

Problem solving

Common pop-up windows have div simulation or replace with window.open, for an already used system, the use of div-mode conversion cost is higher, the use of window.open changes will be less, but also lost its modal.

A simple window.open solution is used here, after all, the cost of replacement is much lower. For the ShowModalDialog usage mentioned above, replace with:

012345 var iwidth = $ ; var iheight = ; var itop = (window screen. Availheight - 30< Span class= "crayon-h" > - iheight / 2< Span class= "Crayon-sy", var ileft = (window. Screen. Availwidth - iwidth) / 2; Var Win = Window.Open("Request.aspx", "Pop-up Window", "Width=" + Iwidth + + iheight + + itop + " , left= " + iLeft + )

In this way, you can open a window similar to the one previously used by ShowModalDialog. But how do you return a value?

In the pop-up page, there are two ways:

1. Directly sets the value of the DOM object for the parent window.

01 window. Opener. Document. getElementById("parentwindowcontrolid"). Value = "Data";

The parent window should have a DOM element with an ID of parentwindowcontrollid.

2. Call the JavaScript function in the parent window, which is handled by the parent window accordingly.

012345  var obj = { id: "id" name: "name" } window. Opener. Doafterxxx (obj ;

The parent window provides a doafterxxx function to do so.

In the long run window.open because of its user experience problem will go to the decline, we still as soon as possible transfer as well.

From Posma's original address "Google Chrome no longer supports ShowModalDialog solutions"

Google Chrome no longer supports ShowModalDialog's solution

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.