CIS 179 – Web Script Programming Lecture Notes

Tutorial 5 - Windows and Frames

The JavaScript Object Model

Window object Window Object defaultStatus  Default text that is written to the status bar
document      A reference to the Document object
frames[]        An array listing the frame objects in a window
history          A reference to the History object.
location         A reference to the Location object
opener          The window object that opens another window
parent          The parent frame that contains the current frame
self              A self-reference to the window object--identical to the window property.
status          Temporary text that is written to the status bar
top              The topmost Window object that contains the current frame
window       A self-reference to the Window object--identical to the self property
name           The name of a window.
alert()                  Displays a simple message dialog box with an OK button
blur()                   Removes focus from a window.
clearTimeout()     Cancels a set timeout
close()                 Closes a window
confirm()             Displays a confirmation dialog box with OK and Cancel buttons.
focus()                Makes a Window object the active window.
open()                Opens a new window
prompt()             Displays a dialog box prompting a user to enter information
setTimeout()       Executes a function after a specified number of milliseconds have elapsed.
Opening and Closing Windows directories         Includes directory buttons
height                Sets the window’s height
location             Includes the URL Location text box
menubar            Includes the menu bar
resizable            Determines if the new window can be resized
scrollbars           Includes scroll bars
status                 Includes the status bar
toolbar              Includes the Standard toolbar
width                Sets the window’s width
Example: window.open(http://www.course.com, "Course", "height=300,width=600");  
<SCRIPT LANGUAGE="JavaScript1.2">
  <!-- Hide from incompatible browsers
  function newWindow() {
    // Open blank window
    window.open("","targetWindow","height=300,width=400");
    // return focus to current window
    return true; // needed so onClick event will put URL in targetWindow
  }
  // Stop hiding from incompatible browsers -->
</SCRIPT>

<A HREF="http://www.monroe.cc.mi.us" onClick="return newWindow();" TARGET="targetWindow">
Visit MCCC's home page. </A>


Try it.

Visit MCCC's home page. 

If the name used in the open() method refers to an existing window then a new window is not created, instead the focus is simply shifted to the existing window.

Timeouts and Intervals setTimeout() - method used to execute JavaScript code after a specified number of milliseconds have elapsed. The syntax for using the setTimeout method is: var timeoutId = setTimeout("code", delay); clearTimeout() - method used to cancel a pending setTimeout() command. The syntax for using the clearTimeout method is: clearTimeout(timeoutId); setInterval() - method used to periodically execute JavaScript code. The number of milliseconds to delay between executions is specified. The syntax for using the setInterval method is: var intervalId = setInterval("code", delay); clearInterval() - method used to stop setInterval() command. The syntax for using the method is: clearInterval(intervalId); Working with Frames and Other Objects
 
Frame - independent scrollable portion of a Web browser window.
<FRAMESET ROWS="50%, 50%" COLS="50%, 50%> <FRAMESET ROWS="100, 50%, *"> <FRAMESET ROWS="50, 50" COLS="50, 50>
<FRAME SRC="frame1.htm">
<FRAME SRC="frame2.htm">
<FRAME SRC="frame3.htm">
<FRAME SRC="frame4.htm">
</FRAMESET>
TARGET Attribute and Frames <A HREF="webpage.html" TARGET="name"> <A HREF="altooboe.html" TARGET="display">altooboe</A><BR>
<A HREF="banjo.html" TARGET="display"></A>banjo<BR>
<A HREF="bassoon.html" TARGET="display"></A>bassoon<BR>
<A HREF="bugle.html" TARGET="display"></A>bugle<BR>
May be rewritten more efficiently using the <BASE> tag, as follows: <BASE TARGET="display">
<A HREF="altooboe.html">altooboe</A><BR>
<A HREF="banjo.html"></A>banjo<BR>
<A HREF="bassoon.html"></A>bassoon<BR>
<A HREF="bugle.html"></A>bugle<BR>
Nesting Frames Frame Formatting Attribute Description

SRC= Specifies the URL to be opened in a frame
NAME= Assigns a name to an individual frame
NORESIZE Disables the user’s ability to resize an individual frame
SCROLLING={yes,no,auto} Determines whether a frame should include scroll bars
MARGINHEIGHT= Specifies the top and bottom margins of the frame in pixels
MARGINWIDTH= Specifies the left and right margins of the frame in pixels

<FRAMESET ROWS="20%", *, 20%">
<FRAME SRC="header.html" NORESIZE SCROLLING=no MARGINHEIGHT=50 MARGINWIDTH=50>
The NOFRAMES tag <FRAMESET ROWS="20%", *, 20%">
<FRAME SRC="header.html" NORESIZE SCROLLING=no MARGINHEIGHT=50 MARGINWIDTH=50>
</FRAMESET>
<NOFRAMES>
You cannot view this Web page because your Web browser is too junky and does not support frames. Get with the 21 century pal.
</NOFRAMES>
The Location Object location.href = "http://www.netscape.com"; Name              Description
hash                 A URL’s anchor
host                 A combination of the URL’s hostname and port sections
hostname         A URL’s hostname
href                 The full URL address
pathname         The URL’s path
port                 The URL’s port
protocol          The URL’s protocol
search             A URL’s search or query portion
The History Object Method             Description
back()                 The equivalent of clicking a Web browser’s Back button
forward()            The equivalent of clicking a Web browser’s Forward button
go()                    Opens a specific document in the history list
The Navigator Object Property                  Returns
appCodeName         The Web browser code name
appName                  The Web browser name
appVersion               The Web browser version
language                   The language, such and English or French, used by the Web browser
platform                    The operating system is use
userAgent                 The user agent string passed from the browser in HTTP requests.
Referring to Frames and Windows frames[1].frames[2] parent.frames[1] <A HREF="chapter01.htm" TARGET="mainwin">
Chapter 1, Introduction
</A>