Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 46 47 48 49 50 51 < 52 > 53 54 55 56 57 58 .. 118 >> Next

If you do decide to implement frames, however, JavaScript can help you make the most effective use of them.
144 Part II: Creating Dynamic Web Pages
Working with Browser Windows
a\ng/
One browser window per Web page is the basic, bare-bones approach to Web development — and for many applications, this approach works just fine. But sometimes you want to display more than one window. For example, imagine you’re a teacher creating a language-arts Web site. You might want to include hyperlinks to vocabulary words so that when your visitors click one of the hyperlinks, the dictionary definition of the hyperlinked word appears in a separate pop-up window.
If you do decide to create a Web page that displays more than one browser window, you need to know how to manipulate the extra windows. For example, you need to know how to position content within the extra windows and close the extra windows. In this section, I show you how to open and manipulate multiple windows from a single Web page.
Displaying new windows — called pop-up windows or just plain pop-ups — can be annoying to your users, so use this skill very sparingly. Also, keep in mind that many users purchase or download free third-party pop-up-blocker software (such as the Google utility that you can find for free at http://toolbar. google.com) or turn off JavaScript support in their browsers to avoid pop-ups. When they surf to your site, these users don’t see your handiwork.
Opening and closing new browser windows
One popular school of thought when it comes to Web design is to do everything you can (within reason, of course) to keep visitors at your site after they find it. For example, adding hypertext links that lead to other sites — although useful — might backfire by scooting your visitors off to other people’s Web sites before they’ve really looked at yours. After all, who knows when (or whether) your visitors will return?
One remedy for this situation is to make your page’s HTML links open the next site in a new browser window. Visitors get to surf freely from your site to others, as appropriate, but without ever leaving your site. It’s a win-win situation! Take a look at Figures 7-1 and 7-2 to see what I mean.
In Figure 7-2, you see how creating a new window leaves the original browser window intact. (Clicking the Close the Window button causes the newly opened window to disappear.)
Chapter 7: Working with Browser Windows and Frames 145
Figure 7-1:
Clicking the Open a Window button opens a window you can prefill with a link.
£] i ipeniiiij .mil closintj .1 new window rfiom JavaScript For Dummies. 4th edition! Micinsott Internet Fxploier j File Eilll View Favorites Tools Help X*
Back - j x" y Search Favorites ^ Media
i Address | C:\em\wrSe\lsfd4e\salpts\llst070t -him____________________________________________________________________________________________jvj Q Go
Figure 7-2:
Loading a URL into a separate window keeps your visitor close to home.
Opening (and closing) a new browser window
[ Open a window ~| [ Close the window |
Opening multiple windows(fiom JavaScript For Dummies. 4th edit... -DSQ
Opening multiple browser windows is easy when you use a function that takes a parameter.
[ Open window #1 | [ Open window #2 ] [ Open window #3 |
01
^Done
^ ■?]
^ My Compute»
10:49 PM
146 Part II: Creating Dynamic Web Pages
Creating such a new window is mighty easy in JavaScript. Listing 7-1 shows you how.
To experiment with the code in Listing 7-1 in your own browser, open the list0701.htm file that you find on the companion CD.
Listing 7-1: Creating (And Destroying) a New Browser Window
<SCRIPT LANGUAGE="JavaScript">
var newWindow = null;
function popItUp() {
newWindow = open("list0702.htm", "secondWindow",
"scrollbars,resizable,width=500,height=400");
}
function shutItDown() {
if (newWindow && InewWindow.closed) { newWindow.close();
}
}
</SCRIPT>
To create a new browser window and load it with a new document automatically, you need to use the open() method associated with the window object, as shown in Listing 7-1. As you can see, the open() method accepts three parameters:
The URL that you want to load into the new window (in this case,
list0702.htm)
The name for this new window (in this example, secondWindow)
A string of configuration options
In this example, the window that you create has scroll bars, has a user-resizing option, and appears with initial dimensions of 500 x 400 pixels. (A quick peek at Figure 7-1 shows you the visible scroll bars. You can verify the other characteristics by loading the file list0701.htm from the companion CD in your own browser.)
To close an open window, all you need to do is invoke the window.close() method by using the name of the open window, like so: newWindow.close();.
Chapter 7: Working with Browser Windows and Frames 147
To see a full description of the open() method, check out the following [fOjl Website:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/
Previous << 1 .. 46 47 48 49 50 51 < 52 > 53 54 55 56 57 58 .. 118 >> Next