• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Frames, Frames, and More Frames > Browser Detection with Frames

Browser Detection with Frames

Another handy way to use frames is to detect browser versions and capabilities. In this example, visitors get stopped at the entrance if they don't have a JavaScript-capable browser. Figure 4.14 shows the site for those who qualify, and Figure 4.15 shows the warning.

Figure 4.14. You've passed the test-Welcome to out site!


Figure 4.15. You need to upgrade your browser before we let you in.


To detect browser capabilities with frames:

  • 							document.write("<FRAMESET COLS='100%,*' FRAMEBORDER='NO' BORDER='0'><FRAME SRC='frame9.html'><\/FRAMESET>")
    							
    
    					  



    This single line of code in Script 4.34 creates a frameset on the fly with just one page (shown in Script 4.35 ). If users don't have JavaScript, they'll fall into the body of the page which will display the warning messages.

Tip

Pages won't appear to be in a frame, but they actually are; it's just that there's only one frame and it takes up the entire window. You'll need to make sure that all the links on the second page set the target to "_top". This will allow the pages that follow to load over the "hidden" frameset.


Tip

Why use this approach instead of just loading document.location.href? If you use that method, the body of the page will start to load and display before the page suddenly flashes and loads a different page. With this method, only the desired page is ever shown.


Tip

In this example, visitors can still decide to check the site out, but they've been warned about the limitations. You can be more specific about what causes a warning by just adding an if() statement around the document.write(). For instance, you might want to block people who aren't running a version 4 or later browser, those who don't have a certain plug-in, or those running an older version of JavaScript.


Script 4.34. This page is a frameset for up-to-data browsers and a regular page for older browsers.


Script 4.35. Here's the page that lets the visitor know they've got an acceptable browser.


  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint