Tips on Targeting While Using Framesets
When using framesets on a website, the most common problem is getting the links to open in the correct frame. This is called targeting and is set by using the target attribute of the anchor tag by giving it a “target” to open their links in. In most websites that do not use frames, you will notice that the target assigned is usually “_blank”, “_new”, “_parent”, “_set”, or “_top”. In a frameset, the target is usually the name of the frame.
Consider the following piece of code:
<frameset rows="50,*"> <frame src="frame1.html" name="nav"> <frame src="frame2.html" name="main"> </frameset>
There are two frames in the above frameset. The first is called “nav” and the second “main”. Try to imagine that the nav frame (frame1.html) is used for navigation, and all links inside it should opened within the main frame (frame2.html). To do this, you would give the links in frame1 the target of “main” as follows: <a href=”page2.html” target=”main”>. However, what if you don’t want to add the target to every link on your navigation page? You can have a global setting for targets by setting a default target in the HEAD of your document, called the “base” target. You simply add the line:
<base target="main">
within the head of the frame1.html page, and all links will then open in the main frame.
Using Frames and Noframes
One of the most misunderstood sections of the frameset tag is “noframes”. In reality, this tag allows people with browsers that do not support of have frames enabled to still view your page. In a typical frameset, the HTML looks like this:
<frameset rows="50,*"> <frame src="frame1.html" name="nav"> <frame src="frame2.html" name="main"> </frameset>
The code above will render a web page with two frames: the top being 50 pixels tall and the bottom being the rest of the page. This would make a nice top navigation bar frameset with the branding, banner, and navigation in the 50 pixel frame. However, if one of your viewers comes to your site and is using a browser that is not support framesets, or has disabled support for framesets, they will get a blank page. So much for the chances of them returning to your site. To make it viewable by them you need to add four more lines of HTML like so:
<noframes> This site is framed, but you can <a href="frame2.html">view a non-framed version</a>. </noframes>
Notice that because you are pointing to the content portion of your frameset (frame2.html) in the noframes section of the page, your site becomes accessible. Always keep in mind that while you may be using the latest version of your favorite browser, your audience may not want to continually download the latest software. Their machine may not support it, or they may not have room to install a 20+ Meg program on their hard drive, or they may be using a mobile phone, etc. Adding four lines of HTML is a simple solution.