15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

196<br />

FRAMESET.cols<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Syntax used in this example is W3C-compatible. To modify this for IE-only, you<br />

replace document.getElementById(“outerFrameset”) with document.all.<br />

outerFrameset and elem.firstChild.nodeValue to elem.innerText. You can<br />

also branch within the scripts to accommodate both styles.<br />

Listing 16-46: Frameset and Script for Hiding/Showing a<br />

Frame<br />

<br />

<br />

Hide/Show Frame Example<br />

<br />

<br />

var origCols<br />

function toggleTOC(elem, frm) {<br />

if (origCols) {<br />

showTOC(elem)<br />

} else {<br />

hideTOC(elem, frm)<br />

}<br />

}<br />

function hideTOC(elem, frm) {<br />

var frameset = document.getElementById(“outerFrameset”)<br />

origCols = frameset.cols<br />

frameset.cols = “0,*”<br />

}<br />

function showTOC(elem) {<br />

if (origCols) {<br />

document.getElementById(“outerFrameset”).cols = origCols<br />

origCols = null<br />

}<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

When a user clicks the hot spot to hide the frame, the script copies the original<br />

cols property settings to a global variable. The variable is used in showTOC() to<br />

restore the frameset to its original proportions. This allows a designer to modify<br />

the HTML for the frameset without also having to dig into scripts to hard-wire the<br />

restored size.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!