Admittedly, all the previous phrases relied on the fact that the browser can open pop-ups. By default, most modern browsers allow pop-ups that are opened from the local server, but block pop-ups that are opened from the Internet. Also, various toolbars with their own pop-up blocking mechanism make the life of developers who rely on pop-ups harder. The bad news first: There is no reliable way to ensure that pop-ups can always be opened. Some blockers support various levels of blocking, some of them allowing certain kinds of pop-ups, some of them disabling all pop-ups. Figure 9.5 shows a typical browser configuration screen. Figure 9.5. A pop-up blocker configuration.
The following code tries to detect whether a pop-up blocker is available: It opens a window and then checks whether it is there. If yes, it will be closed; otherwise, a pop-up blocker is most probably present: Checking for a Pop-Up Blocker (popupcheck.html)
Figure 9.6 shows the result when a pop-up is blocked (also visible from the notification bar on top of the browser's content area). Figure 9.6. A pop-up blocker has been detected.Tip The default behavior of most pop-up blockers is that those pop-ups are allowed that are triggered by a user action. So do not try to call window.open() when the page has loaded, but rather call window.open() when the user clicks on something. But still you have no guarantee that the pop-up will actually appear.
|