Dreamweaver: Making Sure Your Pop-Up Windows Really Pop

One feature that's been part of Dreamweaver for quite a while is the Open Browser Window (OPW for short) behavior. Described simply, the behavior is a JavaScript that opens a page in a new window while at the same time specifying the size, attributes (scrollbars, resize handles. etc.) and name of the window. Once a window is created and named in this manner it can be targetted by additional instances of the OPW behavior or even regualr links.

The problem is that - in Explorer and Firefox - when you target a preexisting window with the OPW behavior, the new page opens but the targetted window does not come to the front (technically, the targetted window does not gain focus). What that means in the real world is that your new page opens but the user doesn't see it because it's hidden. Probably not the solution you were looking for.

Here's an example created using DW's built-in OPW behavior. If you're using Explorer of Firefox (Safari users don't have this problem), click on the first link below and a new window - which I'm naming "popup" - will open. Leave the window open, return to this page and click on the second link.

Open Page 1 then come back and Open Page 2

The second link opens a new page in the existing "popup' window but you won't see it because it's hidden behind this window. To see it and verify that the new page opened, you need to move or minimize this window to get it out ot the way. Please don't close this window, we'd hate to lose you just when things are about to get interesting. Once you're curiosity is satisfied, leave the pop-up window open and return to this page.

What you'd really like to happen is what happens when you click on the link below.

Open Page 3

Notice that the new page opens in the existing "popup" window AND the window comes to the front. Fortunately, all it takes to work this magic is the substitution of a few lines of code in the JavaScript function MM_openBrWindow that Dreamweaver creates to handle the OBW behavior. Here's all you need to do:

  1. In Dreamweaver, using the Behaviors palette, attach the OPB behavior to an object in your page.
  2. Switch to either the Code or Split view.
  3. Near the top of the code of your page, somewhere between the opening head and closing head tags (<head> and </head> respectively) locate the following three lines of code which define the MM_openBrWindow function:

    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
     
  4. Click in the text area below to select the code, copy it and use it to replace the code you located in step 3 above.
  5. That's it! Now whenever you use the Open Browser Window Behavior in your page you can rest assured the window will pop to the front and be visisble. Just remember, since DW inserts the JavaScript in the page (and that's where we customized it), you'll need to make this change on every page where you use the OPW behavior.

Note: When using the links relative to site root option, this customized script will fail using DW's Preview in Browser feature. However it will function properly when uploaded to your web server. Using links relative to document avoids the problem all together.