At first sight, modal windows are great. In contrast to normal windows modals guarantee undivided user attention—the user has to dismiss this window to work with a web page. For this exact reason we’ve used modals heavily in our product to build dialog windows since day one. Not those obnoxious “buy meds online” popups, but rich, bona fide dialog windows.
JavaScript syntax for popping up a modal window is somewhat different from that of a normal one. No big deal, really. You write a basic browser sniffer and pop up a modal in Internet Explorer, and a normal window in other browsers. In IE it’s window.showModalDialog(), and window.open() everywhere else. One can argue Netscape had a “hidden” parameter to make a window modal if the script was signed, etc, but the sake of simplicity let’s say that showModalDialog is a function proprietary to Microsoft.
For two years we’ve been coding around different corks of modals. My buddy at work used his client-side magic to fix various issues of using modals with ASP.NET pages.
For example, if you open two windows of the exact same height and width—a modal one and a plain one—they will be of different physical size, which you have to accommodate with some math so the two would actually cover more or less the same area on your screen.
Next, modals are difficult when you need a page within them to post back, which ASP.NET pages do a lot. Neither can you access the window opener because in a modal it makes no sense. These are no small problems.
More Weirdness
There was a very strange bug we observed, but I haven’t been able to reproduce it in a test project. The setup was as follows: we had a page displaying a data grid. You could select several items in the grid and click a button below it. The page would post back, generate a report on these selected items, and pop up a modal window with a fancy chart. At that time we had all pages automatically store their view state in the database.
The weird thing is the page that built the report would have its view state corrupted after it popped up a modal! This is was a difficult bug to track down and to this day we don’t know how (and why!) view state and modal windows are related. The solution was simple enough—if the report page was a plain window the trouble with view state would go away.
Conclusion
The lesson I learned: modals are not worth the trouble. They don’t work across browsers well enough, they behave differently, and ASP.NET pages have issues when opened in modals. Having spent this much time with modals, we decided to pull the plug on them for good. No more modals!