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

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 .. 47 48 49 50 51 52 < 53 > 54 55 56 57 58 59 .. 118 >> Next

Controlling the appearance of browser windows
In this section, I show you how to customize the windows that you create — specifically, how to create multiple windows and how to position new windows with respect to existing windows.
Creating multiple windows
Creating multiple windows by using JavaScript is almost as easy as creating a single window. The only difference? To create multiple windows, you want to create a custom function that allows you to “rubber-stamp” as many windows as you want. The code in Listing 7-2 shows you how.
Listing 7-2: Using a Custom Function to Create Multiple Browser Windows
var newWindow = null;
function popItUp(win) {
var windowFile = win + ".htm” newWindow = open(windowFile, win,
<H2>Opening multiple browser windows is easy when you use a function that takes a parameter../H2>
.INPUT TYPE=”button” VALUE=”Open window #1” onClick=”popItUp('one')”>
.INPUT TYPE=”button” VALUE=”Open window #2” onClick=”popItUp('two')”>
.INPUT TYPE=”button” VALUE=”Open window #3” onClick=”popItUp('three')”>
148 Part II: Creating Dynamic Web Pages
The code in Listing 7-2 defines a function called popItUp() that takes a single parameter. When a user clicks the Open Window #1 button, the 'one' string is sent to the popItUp() function. The popItUp() function uses this incoming parameter to identify the name of the window (one) as well as the HTML file to open in the window (one.htm).
You can experiment with the code in Listing 7-2 in your own browser by opening the list0702.htm file, which you find on the companion CD.
Positioning new windows
When you open a new browser window, the browser decides where to place that window, as shown previously in Figure 7-2. However, you can tell the browser exactly where to put it — by using JavaScript, of course!
The following code shows you one way to do just that:
var leftPosition = screen.width/2
var newWindow ="one.htm”, "secondWindow”,
"width=225»height=200,left=” + leftPosition + ",top=0”)
The window placement positions that you can control are left and top. The JavaScript code that you see here calculates the value for the left position — in this case, the calculation is equal to half the screen width. The calculated value is stored in the variable leftPosition and used as the value of the left attribute expected by the function. The upshot? The left side of the newly displayed window appears exactly halfway across the screen.
Working with Frames
Scripted frames are a valuable addition to any Web developer’s tool belt. By using a combination of HTML frames and JavaScript, you can present a static, clickable table of contents on one side of a page; then, on the other side of the page, you can present the text that corresponds with each table of contents entry.
Check out Figure 7-5 to see an example of a simple framed table of contents on the left side of the page and content on the right.
One of the benefits of frames is that they allow you to display different HTML files independently from one another. So, for example, as Figure 7-3 shows, the left frame stays visible — even if the user scrolls the right frame. Plus, clicking a link in the frame on the left automatically loads the appropriate content in the frame you see on the right.
Chapter 7: Working with Browser Windows and Frames 149
Figure 7-3:
Using frames to show a site index and the related content.
|ç_] - Wiiting for the Web - What every wiiter MUST know about e-publishing - Microsoft Internet Explorer SSDQj
File Edit View Favorites Tools Help
Bdck * ^ ^ y Search Favorites g g- a • □ я ei Ci
Address C:\em\wnte\isfd4e\scripts\llst07O3.htm v Д Go
© e-promotion e-publishing e-markets e-courses resources who's emityv"?
form* Vi
Why cjn’t I gat Published?
The 3 tuoes of cpubliihcrs
Savvy new way fo market and sell your writing -or a writer's worst nightmare?
Electronic publishing, or e-publishing, gives authors the means to promote, sell, and distribute their own work - to readers all over the world
What an intoxicating democracy. For every manuscript, a publisher! Instantly what Every wnter must
No nail-biting. No waiting years for your dog-eared manuscript to make the rounds of Know About EPubibhinj
the top New York publishing houses No flumes of rejection slips in your mailbox
That's quite a contiast to the traditional publishing industry, where stnct acquisition gatekeepers wield the unilateral power to decide which titles have potential and which don't (often based on such literary considerations as whether or not you're a celebrity).
Unfortunately, the low barriers to entry that began and continue to fuel this new industry make it possible for any Tom. Dick, or Hatiy with fifty bucks and a phone connection to set up shop as an e-publishei And despite wild claims that e-publishing has "arrived," the technologies on which e-publishing depends -hardware that lets you print and bind a single book on demand, for instance, and
Previous << 1 .. 47 48 49 50 51 52 < 53 > 54 55 56 57 58 59 .. 118 >> Next