Prev | Current Page 263 | Next

Craig Grannell

"The Essential Guide to CSS and HTML Web Design"

In all cases, JavaScript can be added either to external JavaScript
files attached to your HTML documents (which is the preferred method; see the section
???Attaching favicons and JavaScript??? in Chapter 2) or in a script element within the head
of the HTML page:

Specifically, we??™ll look at pop-up windows, swapping images using JavaScript, and toggling
div visibility with JavaScript.
Creating a pop-up window
Pop-up windows are mostly an annoyance, especially when automated and when they
remove browser controls. However, they are occasionally useful, such as for providing a
user with brief access to terms and conditions without interrupting a checkout process.
Some portfolio sites also use pop-up windows to display larger versions of images
(although we??™ll later see a better method of creating an online gallery).
Should you require a pop-up window of your very own, the JavaScript is simple:
function newWindow()
{
window.open("location.html");
}
And this HTML calls the script using the onclick attribute:
Open a
?? new window!

Note how the href attribute still has a value, which caters to users with JavaScript disabled
(loading the document into the current window). The return false part of the onclick
value ensures the href value is ignored for browsers with JavaScript activated (otherwise
both the original and pop-up window would display with the new web page).


Pages:
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275