48
Tutorial 5 Windows and Frames Section B - Working with Frames and Other Objects Go to Other Objects

Tutorial 5 Windows and Frames Section B - Working with Frames and Other Objects

  • Upload
    rania

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

Tutorial 5 Windows and Frames Section B - Working with Frames and Other Objects. Go to Other Objects. Tutorial 5B Topics. Section B - Working with Frames and Other Objects How to create frames How to use the TARGET attribute How to create nested frames How to format frames - PowerPoint PPT Presentation

Citation preview

Page 1: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Tutorial 5

Windows and Frames

Section B - Working with Frames and Other Objects

Go to Other Objects

Page 2: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Tutorial 5B Topics

• Section B - Working with Frames and Other Objects– How to create frames– How to use the TARGET attribute– How to create nested frames– How to format frames– About the NOFRAMES tag– About the Location object– About the History object– About the Navigator object– How to reference frames and windows

Page 3: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– Frame

• Independent, scrollable portions of a Web browser window, with each frame capable of containing its own URL

• JavaScript treats each frame in an HTML document as an independent window

• Each frame has its own Window object

Page 4: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– <frameset> tag

• A frame container • Can only contain <frame> and other

<frameset> tags– Others are ignored

• Do not use <body> tags

Page 5: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– Frames can be created in rows,

columns or both– <frameset> attributes

• ROWS– Determines number of horizontal frames to

create

• COLS– Determines number of vertical frames to create

Page 6: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 7: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 8: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 9: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– Frame dimensions

• Can be specified in:– Pixels

» Absolute sizing– Percentages

» Relative sizing» Asterisk (*) designates remainder of visible

window

Page 10: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– <frame> tag

• Used to specify options for individual frames

– e.g., URLs

• Placed within <frameset> tags• Can be assigned a name using the NAME

attribute, which can be used as a target for a hyperlink

Page 11: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Creating Frames– Example:

<html><title><head>Frame Example</head></title><frameset rows=“50%, 50%” cols=“50%, 50%”>

<frame src=“FirstURL.html”><frame src=“SecondURL.html”><frame src=“ThirdURL.html”><frame src=“FourthURL.html”>

</frameset></html>

Page 12: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 13: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Using the TARGET attribute– Menu systems

• Popular use of frames• One frame to contain the hypertext links• Second frame to contain selected URLs

– TARGET attribute• Determines in which frame or Web browser window

a URL opens• <base> tag

– Used to specify a default target for all links in a document

Page 14: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 15: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 16: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Nesting Frames– Nested frame

• Frame contained within another frame• URLs of frames are loaded in the order in

which each <frame> tag is encountered

Page 17: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Nesting Frames– Example:

<frameset rows=“50%, 50%” cols=“50%, 50%”><frame src=FirstURL.html”><frameset rows=“50%, 50%” cols=“50%,

50%”><frame src=“FirstURL.html”><frame src=“SecondURL.html”><frame src=“ThirdURL.html”><frame src=“FourthURL.html”></frameset><frame src=“ThirdURL.html”><frame src=“FourthURL.html”>

</frameset>

Page 18: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 19: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Nesting Frames– Example:

<frameset cols=“200, *”><frame src=“InstrumentsList.html”

name=“list”><frameset rows=“75%, *>

<frame src=“Instruments.jpg” name=“picture”>

<frame src=“Welcome.html” name=“description”>

</frameset></frameset>

Page 20: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 21: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Frame Formatting– <frame> attributes

• Several attributes are available to change a frame’s appearance and behavior

Page 22: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 23: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Frame Formatting– Example:

<frameset rows=“20%, *, 20%”><frame src=“header.html” noresize

scrolling=no><frame src=“body.html”><frame src=“navigationbar.html”

noresize scrolling=no></frameset>

Page 24: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 25: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 26: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The <noframes> tag– Some older browsers are incompatible with

frames• <noframes> tag displays an alternate message to users

of those browsers

– Example:<frameset rows=“20%, *, 20%”>

<frame src=“header.html” noresize scrolling=no><frame src=“body.html”><frame src=“navigationbar.html” noresize

scrolling=no></frameset><noframes> You cannot view… </noframes>

Page 27: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The Location Object– Allows you to change to a new web

page from within JavaScript code– Contains several properties and

methods for working with the URL of the document currently open in a Web browser window

Go to First Slide

Page 28: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The Location Object– When you modify any property of the

Location object, you generate a new URL

– The web browser will then automatically attempt to open that new URL

Page 29: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 30: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

The Location Object

• Example:location.href = “http://www.ithaca.edu”

• Will cause the browser to open the ithaca home page

Page 31: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 32: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

The Location Object

• The assign() method is same as the href property:location.assign(“http://www.ithaca.edu”)

Will cause the ithaca home page to be loaded in the browser.

• The reload() method is same as the reload button– If no argument or argument is false then the page is

reloaded only if it has changed– If argument is true then the page will always reload

Page 33: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

The Location Object

• The replace() method is similar to the href property:location.replace(“http://www.ithaca.edu”)– Difference: replace actually overwrites one

document with another– Also replaces the old URL entry in the web browser’s

history list.– The href property opens a different document and

adds it to the history list.

Page 34: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

The Location Object

• Example:– Redirect.html

Page 35: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The History Object– Maintains a history list of all the documents

that have been opened during the current Web browser session

– Security features• History object will not display the URLs on the

list• May traverse the history list using

methods/properties• In IE: only allows navigation if page is in same

domain

Page 36: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 37: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The History Object Example:

<input type="text" Name="newURL">

<input type="button" name="goto" value=" Go To "onClick="parent.main.location.href=document.controls.newURL.value;">

<input type="button" name="next" value=" Next URL "conClick="parent.main.history.forward();">

<input type="button" name="previous" value=" Previous URL "conClick="parent.main.history.back();">

Page 38: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The Navigator Object– Used to obtain information about the

current web browser– Typically used to identify browser

Page 39: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 40: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

•The Navigator Object–Example:

<script language=“javascript”>document.writeln(“Browser code name: “ + navigator.appCodeName);document.writeln(“Web browser name: “ + navigator. appName);document.writeln(“Web browser version: “ + navigator. appVersion);document.writeln(“Operating platform: “ + navigator. platform);document.writeln(“User agent: “ + navigator. userAgent);

</script>

Page 41: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The Navigator Object– Shortcut:

with (navigator) {document.writeln(“Browser code name: “ +

appCodeName);document.writeln(“Web browser name: “ +

appName);document.writeln(“Web browser version: “ +

appVersion);document.writeln(“Operating platform: “ +

platform);document.writeln(“User agent: “ + userAgent);

}

Page 42: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• The Navigator Object– testing:

If (navigator. appName == “Microsoft Internet Explorer”) {location.href =

“www.ithaca.edu/jbarr/myIE.html”;}Else

location.href = “www.ithaca.edu/jbarr/myFireFox.html”;

Page 43: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

•The Navigator Object–Example:

•NavigatorObjects.html•browserProperties.html

Page 44: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Referring to Frames and Windows– Frames object

• Includes a frames[ ] array that contains all the frames in a window

– frames[0], frames[1], etc.

– Parent property• Used to refer to a frame within the same frameset

– parent.frames[0], parent.frames[1]

– Top property• Used to refer to the topmost frame in a frameset

Page 45: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Referring to Frames and Windows– Example:

<frameset rows=“50%, *, 50%”><frame src=“frame1.html”

name=“FirstFrame”><frame src=“frame2.html”

name=“SecondFrame”> </frameset>

Page 46: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Referring to Frames and Windows– Example: frameReferences.html

<P><INPUT TYPE="button" VALUE=" Get thirdFrame's URL "onClick="alert(parent.frames[2].location.href);"></P>

<P><INPUT TYPE="button" VALUE=" Get the frame set document's URL "onClick="alert(top.location.href);">

Page 47: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects
Page 48: Tutorial 5 Windows and Frames Section B -  Working with Frames and Other Objects

Working with Frames & Other Objects

• Preventing frames:– Example: BreakoutCheck.html

if (window != top)top.location.href=location.href

– Changes the top window content to be the content of the current window