N
news frontiernet.net
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC
HTML book, version one that is on pages 94-96. This is part of my effort to
learn JavaScript.
I checked each byte and position back against the book for syntax errors but
still cannot get this script to work.
I tells me that;
1. Line 49 has a missing ";" at bye 13
2. Line 89 has a missing object at byte 1
How do I find the problems with this script? I am guessing at the line
numbers and 49 does not seem to be even near anything with a ";" in it in
the book.
If I could display the results of each function, then I would know which
functions do work and be able to isolate my efforts on just those that dont.
How does use JavaScript to display the results of each of these defined
JavaScript functions?
Here is the full code of of the example 4-6 as I have it keyed;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE="JavaScript">
// ** Begin library code better placed in an external API ***
// set global variable for browser detection and references building
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >=4){
if (navigator.appName == "Netscape"){
isNav = true
} else {
isIE = true
coll = "all."
styleObj = ".style"
}
}
// Utility function returns rendered height of object content in pixels
function getObjHeight(obj) {
if (isNav) {
return obj.clip.height
} else {
return obj.clientHeight
}
}
// Utility function returns rendered width of object content in pixels
function getObjWidth(obj) {
if (isNav) {
return obj.clip.width
} else {
return obj.clientWidth
}
}
// Utility function returns the available width space in browser window
function getInsideWindowWidth() {
if (isNav) {
return window.innerWidth
} else {
return document.body.clientWidth
}
{
// Utility function returns the available content height space in browser
window
function getInsideWindowHeight() {
If (isNav) {
return window.innerHeight
} else {
return document.body.clientHeight
}
}
// Utility function to position an element at a specific x,y location
function shiftTo(obj, x, y) {
if (isNav) {
obj.moveTo(x,y)
} else {
obj.pixelLeft = x
obj.pixelTop = y
}
}
// ** End Library code ***
// center an element named banner in the current window/frame, and show it
function centerIt() {
// 'obj' is the positionable object
var obj = eval("document." + coll + "banner" + styleObj)
// 'contentObj' is the element content, necesary for IE 4 to return the
true width
var contentObj = eval("document."+ coll + "banner")
var x = Math.round((getInsideWindowWidth()/2)-(getObjWidth(contentObj)/2))
var y =
Math.round((getInsideWindowHeight()/2)-(getObjHeight(contentObj)/2))
shiftTo(obj, x, y)
obj.visibility = "visible"
}
// Special handing for CSS-P redraw bug in Navigator 4
function handleResize() {
if (isNav) {
// causes extra re-draw, but must do it to get banner object color redrawn
location.reload()
} else {
centerIt()
}
}
</SCRIPT>
</head>
<body onLoad="centerIt()" onResize="handleResize()">
<DIV ID="banner" STYLE="position:absolute; visibility:hidden; left:0; top:0;
background-color:yellow; width:1; height:1">
<P ID="txt" STYLE="position:absolute; left:0; top:0; font-size:36pt;
color:red">
Congratulations!
</P>
</DIV>
</body>
</html>
HTML book, version one that is on pages 94-96. This is part of my effort to
learn JavaScript.
I checked each byte and position back against the book for syntax errors but
still cannot get this script to work.
I tells me that;
1. Line 49 has a missing ";" at bye 13
2. Line 89 has a missing object at byte 1
How do I find the problems with this script? I am guessing at the line
numbers and 49 does not seem to be even near anything with a ";" in it in
the book.
If I could display the results of each function, then I would know which
functions do work and be able to isolate my efforts on just those that dont.
How does use JavaScript to display the results of each of these defined
JavaScript functions?
Here is the full code of of the example 4-6 as I have it keyed;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE="JavaScript">
// ** Begin library code better placed in an external API ***
// set global variable for browser detection and references building
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >=4){
if (navigator.appName == "Netscape"){
isNav = true
} else {
isIE = true
coll = "all."
styleObj = ".style"
}
}
// Utility function returns rendered height of object content in pixels
function getObjHeight(obj) {
if (isNav) {
return obj.clip.height
} else {
return obj.clientHeight
}
}
// Utility function returns rendered width of object content in pixels
function getObjWidth(obj) {
if (isNav) {
return obj.clip.width
} else {
return obj.clientWidth
}
}
// Utility function returns the available width space in browser window
function getInsideWindowWidth() {
if (isNav) {
return window.innerWidth
} else {
return document.body.clientWidth
}
{
// Utility function returns the available content height space in browser
window
function getInsideWindowHeight() {
If (isNav) {
return window.innerHeight
} else {
return document.body.clientHeight
}
}
// Utility function to position an element at a specific x,y location
function shiftTo(obj, x, y) {
if (isNav) {
obj.moveTo(x,y)
} else {
obj.pixelLeft = x
obj.pixelTop = y
}
}
// ** End Library code ***
// center an element named banner in the current window/frame, and show it
function centerIt() {
// 'obj' is the positionable object
var obj = eval("document." + coll + "banner" + styleObj)
// 'contentObj' is the element content, necesary for IE 4 to return the
true width
var contentObj = eval("document."+ coll + "banner")
var x = Math.round((getInsideWindowWidth()/2)-(getObjWidth(contentObj)/2))
var y =
Math.round((getInsideWindowHeight()/2)-(getObjHeight(contentObj)/2))
shiftTo(obj, x, y)
obj.visibility = "visible"
}
// Special handing for CSS-P redraw bug in Navigator 4
function handleResize() {
if (isNav) {
// causes extra re-draw, but must do it to get banner object color redrawn
location.reload()
} else {
centerIt()
}
}
</SCRIPT>
</head>
<body onLoad="centerIt()" onResize="handleResize()">
<DIV ID="banner" STYLE="position:absolute; visibility:hidden; left:0; top:0;
background-color:yellow; width:1; height:1">
<P ID="txt" STYLE="position:absolute; left:0; top:0; font-size:36pt;
color:red">
Congratulations!
</P>
</DIV>
</body>
</html>