Home > Articles > Programming

  • Print
  • + Share This
Like this article? We recommend

Improving the Pop-Up Pages

There are several ways in which a web application can figure out whether a page should be presented in a pop-up format or in a full-blown format with logo, navigation bars, sidebars, and footers (let’s call them non-content elements):

  • On the server, you can check the referer HTTP header. If the referring page belongs to the same web, the page is presented in a pop-up format; otherwise it includes the non-content elements. This method isn’t completely reliable, however, as it depends on the browser’s proper handling of the referer header.
  • On the browser, you can check the window.opener property. If the property is set, the page is shown in a pop-up window and the non-content elements can be hidden. This approach is more reliable, but the page might flicker during the load process unless you hide all the non-content elements by default and show them only if needed (which would yet again hurt the visitors without JavaScript). Furthermore, as the non-content elements are always downloaded into the browser window, the download time is increased.
  • You could also add a parameter to the query string when a page is launched in a pop-up window. The server-side application would then check this parameter and omit the non-content elements if the parameter is present. The query string can also be checked on the browser (with the location.search property), so this method also works for static pages.

The last method is the most robust; it’s the one we used in our solution. It requires only a single change in the convertPopupLinks function, adding the popup parameter to the pop-up window query string:

popupLink.href = "javascript:popup(’" + href+((href.indexOf("?") < 0) ? "?" : "&") + "popup’)" ;

If your server-side application is well organized and has all the non-content elements grouped in an include file, the change in the pop-up pages is minimal; you just need to check for the presence of the popup parameter and execute the code in the included files if it’s present. The ASP version of the server-side code is shown in Listing 2.

Listing 2 Adding non-content elements to pop-up pages.

<% 
Dim isPopup
isPopup = Request.QueryString("popup").count > 0

If Not isPopup Then %>
<!-- #include file=commonHeaderElements.asp -->
<% End If %>
... page content ...
<% If Not isPopup Then %>
<!-- #include file=commonHeaderElements.asp -->
<% End If %>
  • + Share This
  • 🔖 Save To Your Account