« Cafe Vergnano, 62 Charing Cross Road, London | Main | 49th London Film Festival »
showModalDialog in Firefox and frames
October 05, 2005Keywords: greasemonkey code javascript webdev
I use Firefox exclusively and every now and then I come across a site that is crippled. This means that parts of it will not work in Firefox because the site is using some kind of IE only functionality.
One example is the function showModalDialog. This will create a modal pop-up when using IE but because it is not a W3C standard, it is not implemented in Firefox (Mozilla) and will just cause a JavaScript error.
Greasemonkey is a very powerful extension for the Firefox browser that lets you inject your own JavaScript into any web page. This includes overriding any present functionality.
While this can be used to bypass poor security implementations a far better use is to fix usability errors or mash together information from different sites.
I present you my first Greasemonkey script. It is a workaround for showModaldialog by replacing it with a standard confirm dialog: "Are you sure?".
// Author: David KasparInstall the script
// ==UserScript==
// @name showModaDialogFix
// @description Implement show modal dialog in Firefox
// @include http://<enter your site(s) here>
// ==/UserScript==
window.showModalDialog = function() {
return window.confirm("Are you sure?");
}
If the site you are visting is using frames, you may have to use the below version and insert the name of the frame that is calling the showModalDialog function:
if (window.frames.frameNameHere) {
window.frames.frameNameHere.showModalDialog = function() {
return window.confirm("Are you sure?");
}
}
Update 04/05/2007
No progress with Firefox modal windows so instead a work-around: forced focus on pop-up.
During the latest cross browser compatibility push at our company, a team member devised this work-around and it works sufficiently in all browsers we tested (IE6, IE7, FireFox 2, Safari, Opera).
The idea is to force focus on the pop-up window. This is achieved with the javascript function window.focus().
This method will not work if the user has JS switched off but since JS is a basic requirement for our services, we can expect JS to always be on.
Related entries:





aubery Says:
December 5, 2005 05:58 AM
That good to know but using showModaDialog has it advantages is there a command with firefox that does the think
Geekman Says:
June 5, 2006 10:13 PM
The modal=yes argument does work in Firefox 1.5
Naveen Malik Says:
June 7, 2006 01:27 PM
Your this solution is not working.
I am not succeed to create a model dialog when i am using fire fox as my web browser.
Please suggest me some solution for it.
Sivakumar Says:
July 20, 2006 08:25 AM
How to make model dialog both in IE and Mozila?
B4rT Says:
August 18, 2006 12:07 PM
Here is the solution for your problem:
http://www.hedgerwow.com/360/dhtml/dialog_window/dialog_window.htm
Unfortunatelly it desn't work for Firefox 2 (I don't know yet why)
Bartek
Shawn Says:
August 23, 2006 03:59 PM
personally.. I feel Firefox's implementation of the modal feature is better.
It allows interaction with the parent window which is what I need..
If I wanted to have a window Always-On-Top AND Always-In-Focus, I'd have used javascript to refocus the window onBlur.
Vaidas Says:
October 16, 2006 11:09 AM
In IE is 2 types of modals Showmodaldialog, showmodlessdialog.
I believe mozila modal = showmodlessdialog (so you can interact with parent window).
Michel Says:
October 18, 2006 10:55 AM
I need in Mozilla show modal and I can't interact with parent window.
Uday Says:
December 4, 2006 02:12 PM
Can anyone give me the equivalent of window.ShowModalDialog in Mozilla browser.
Rigre G. Grciandía Sóñora Says:
February 4, 2007 05:33 PM
In FF you can't use showModalDialog function, also you can simulate in some manner a popup using a div tag inside your page.
The problem with this solution is that after you open the div tag you can access to the rest of the components in your page (not exactly the desirable behavior associated to a modal form).
Maybe you can implement in some manner a java script function that invalidate events ion the rest of controls of your page.
Stu Says:
March 29, 2007 08:45 AM
W3C is a lovely implementation but as usual all things being equal some are more equal than others. I think FF needs to catch up with IE7. I could program a plug-in to hook the showmodaldialog but then the problem is people would need to install it which will be unlikely.
The DOM is great because now I only have to code JS in 1 way for all browsers however I still have to implement a different W3C CSS for each type of browser! fix that then I be happy.
Scorpy Says:
March 30, 2007 10:35 AM
showModalDialog functionality can be acheived by window.open method and the page u are opening write set the focus on onBlur() event may be this will solve the problem
vik Says:
April 4, 2007 06:12 PM
hie scorpy
can u plz give me an example for how to do this? i mean a code example of setting focus to onblur()
vik
js Says:
May 9, 2007 08:03 AM
i have created Menu having sub menu, using javascript and css. It is working properly on IE but not showing sub menus in Mozila Firefox.
so kindly send me a code through which i could remove this problem.
Steve Says:
June 5, 2007 12:49 AM
Using onblur="window.focus();" in the body is a nice idea, unfortunately it just doesn't always work. If the user plays around with clicking other windows in the taskbar, you can find your way back to the parent dialog, which will then accept user input (which would more than likely take away the point of using a modal dialog). Also, it gets annoying when trying to access other non-browser applications and the "modal" dialog keeps wanting to pop up in front (it should be only tied to the parent browser). I think more browsers should support some flavor of this functionality (for those who hate modal dialogs, don't tell me you don't use CONFIRM or ALERT boxes. If used sparingly, I believe modal dialogs have a place, but feel free to disagree).
dg Says:
June 21, 2007 11:34 AM
for Mozilla browser try using the below code
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
window.open('test.html?params='+ params +'', 'TEST', 'chrome,centerscreen,dependent=NO,dialog=YES,modal=YES,resizable=NO,scrollbars=NO,location=0,status=0,menubar=0,toolbar=0,height='+Height+',width='+Width+',left='+X+',top='+Y);
hope this helps
dg Says:
June 22, 2007 12:17 PM
function Open_Window() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
var params = 'a|b|c';
window.open('test.htm?params='+ params +'', 'test', 'chrome,centerscreen,dependent=YES,dialog=YES,modal=YES,resizable=NO,scrollbars=NO,location=0,status=0,menubar=0,toolbar=0');
}
this code perfectly work for mozilla firefox 2.0.0.3
KJS Says:
June 27, 2007 01:56 AM
How to get response back from the modal window? How do I know if user has clicked 'Yes' or 'No' button in modal window.
DJ Says:
July 11, 2007 06:59 AM
dg... if i run ur code then line "netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');"
gives an error "Error: uncaught exception: A script from "http://localhost:1010" was denied UniversalBrowserWrite privileges"
do i need to configure something before running the same?
Bhavana Says:
July 16, 2007 11:50 AM
I am facing a similar problem. I want to display a modal dialog. I used the showModalDialog function. This works in IE but doesn't work in Mozilla.
Please help.
dg Says:
July 19, 2007 10:45 AM
hi .... checked this code ..... works fines
save the below code in a html file and check it
[html]
[head]
[style]
[/style]
[script]
function Open_Window() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
var params = 'a|b|c';
window.open('test.htm?params='+ params +'', 'test', 'chrome,centerscreen,dependent=YES, dialog=YES,modal=YES,resizable=NO,scrollbars=NO, location=0,status=0,menubar=0,toolbar=0');
}
[/script]
[/head]
[body]
[input type="button" value="Load XUL Test Window" onclick="Open_Window()"]
[/body]
[/html]
replace square brackets with html tag
Dave P Nottingham Says:
July 23, 2007 04:44 PM
If there is an alternative to ShowModalDialog for bringing multiple amounts of data back from the child to parent window I'd love to hear about it! Window.open works fine for just one selected item but not multiples.
propecia effective Says:
July 24, 2007 08:25 PM
propecia rogain 6proscar propecia
Mano Says:
August 27, 2007 01:04 PM
Hi All,
In my project i want a window behave like a modal window with out using modal=yes in firefox.
is it possible?
FBM Says:
November 14, 2007 01:23 PM
Hi Dg your code doesn't work
Al Says:
December 26, 2007 11:17 PM
you need to enable a part of your FF about:config file for that code to work
noe Says:
March 12, 2008 04:56 AM
thanks dg, your script work fine . you are the man. cool :D
Dmitri Farkov Says:
March 14, 2008 05:37 PM
What you guys are searching for is a Lightbox. A Lightbox - a JavaScript-powered modal dialog. Looks pretty, compatible with tons of browsers. Just search on Google.