How to make Chrome support showModalDialog
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to make Chrome support showModalDialog相关的知识,希望对你有一定的参考价值。
My leader has solved this problem, 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 = window.showModalDialog(url,arguments,dialogSettings); dialog.callback = 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 dialog arg = arg || null; //arguments to a dialog opt = opt || ‘dialogWidth:300px;dialogHeight:200px‘; //options: dialogTop;dialogLeft;dialogWidth;dialogHeight or CSS styles × var dialog = 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 : "") +‘></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>‘; var dlgBodyWin = 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();
});
dialog.showModal();
dialog.callback = function(){};
dialog.addEventListener(‘close‘, function() {
var returnValue = dlgBodyWin.returnValue;
top.window.document.body.removeChild(dialog);
dialog.callback(returnValue);
});
return dialog;
};
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 make Chrome support showModalDialog的主要内容,如果未能解决你的问题,请参考以下文章
[转]Android How to Download and Make Volley.jar
How to make dictionary work in TexStudio
How To Make a Music Visualizer in iOS