How to do Chrome support ShowModalDialog

Source: Internet
Author: User

My leader have solved this problem and let's see the trick.

For IE, in main window:

var result = window.showModalDialog (url,arguments,dialogsettings); alert (result);

Modaldialog, sub window:

Window.returnvalue = "abc"; window.close;

The above codes work fine in IE, we can fix to this:

In main window:

var dialog =function(p_result) {
alert (P_result);

Modaldialog, sub window:

Window.returnvalue = "abc";
__window_close ();

and add some code to fix prototype of Chrome:

window.showModalDialog =function(URL, arg, opt) {URL= URL | | ‘‘;//URL of a dialogarg = ARG | |NULL;//arguments to a dialogopt = opt | | ' dialogwidth:300px;dialogheight:200px ';//options:dialogtop;dialogleft;dialogwidth;dialogheight or CSS styles &times;            varDialog = Top.window.document.body.appendChild (document.createelement (' dialog ')); Dialog.setattribute (' Style ', Opt.replace (/dialog/gi, '));dialog.innerhtml= ' <div id= ' Dlg-head "class=" Dlghead "><div id=" Dlg-title "' + (arg && arg.title? Arg.title:" ") + ' >&lt ;/div><div id= "Dlg-controlbox" ><a href= "javascript:void (0);" id= "Dlg-closebutton" class= " Controlboxbutton "></a></div></div><div id=" Dlg-body "class=" DlgBody "><iframe id=" Dialog-body "src=" ' + URL + ' "style=" border:0; width:100%; height:100%; " ></iframe></div> '; varDlgbodywin = Dialog.queryselector (' #dialog-body '). Contentwindow; Dlgbodywin.dialogarguments=Arg; Dlgbodywin.addeventlistener (' Load ',function(e) {dialog.queryselector (' #dlg-title '). InnerText =DlgBodyWin.document.title;            }); Dialog.queryselector (' #dlg-closebutton '). AddEventListener (' click ',function(e) {e.preventdefault ();
Dialog.close ();
});

function

Dialog.addeventlistener (' Close ', function () {
var returnvalue = Dlgbodywin.returnvalue;
Top.window.document.body.removeChild (Dialog);

Dialog.callback (returnvalue);
});


Return
};

function __window_close () {
if (__ISGG) {//in Chrome
var dialogs = top.window.parent.document.getElementsByTagName ("dialog");
if (Dialogs.length > 0) {
Dialogs[dialogs.length-1].close ();
}
} else {
Window.close ();
}
}

Use HTML5 Dialog to implement ShowModalDialog, awesome.

How to do Chrome support ShowModalDialog

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.