Forum Moderators: not2easy
The instructions state: "Inside the <BODY> tag itself, throw in the following onLoad event handler, as follows:"
<body onLoad="show_clock()">
My question is: how do I modify this code to work in my .CSS/XHTML document?
Let me clarify a few things. First, the doctype: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Second, the code that I am instructed to insert into the HTML document is as follows:
<body onload="show_clock()">
<script src="liveclock.js" type="text/javascript"></script>
If I insert this into my XHTML document, it works just fine.
BUT, it won't validate:
1.Error Line 90 column 27: document type does not allow element "body" here.
<body onload="show_clock()">2. Line 90 column 0: start tag was here.
<body onload="show_clock()">
</head>
<body onload="show_clock()">
<script src="liveclock.js" type="text/javascript"></script>
-Now on to problem 2: how do I get rid of the annoying IE7 pop-up:
To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer. Click here for options...
<html>
<head>
<title>Page Title</title>
<script src="liveclock.js" type="text/javascript"></script>
</head>
<body onload="show_clock()">
<!-- rest of page... -->
</body>
</html>
You could also remove the onload event handler from your HTML body element and add a line to the top of your included liveclock.js file, as rocknbil suggests - this does the same thing, but helps keep your JS and HTML separate.
-Now on to problem 2: how do I get rid of the annoying IE7 pop-up:
But "it's a feature of Microsoft Internet Explorer"! You get that 'security warning' in IE whenever you try to run JavaScript locally (ie. not on a webserver) - in the local security zone. This doesn't effect other browsers. If you were to upload your page to a website you won't get the error.
You can, however, get around the problem if you need to run JS locally (from a CD perhaps) by adding, what Microsoft calls the 'Mark Of The Web' (MOTW) to every webpage that executes JS. This takes the form of a special HTML comment you can place near the top of your HTML file (below the DOCTYPE) which forces the page to run in a different security zone:
eg:
<!-- saved from url=(0014)about:internet -->
For more info, Google for "Mark of the Web".
[edited by: penders at 6:16 pm (utc) on July 21, 2007]
I have placed the <script> element within the <head> section, moved the onload event handler to the liveclock.js file AND disabled the IE7 Active X warning ... and the page validates!
If anyone wants to know how to turn off the ActiveX warning:
To disable the message, Start > Control Panel > Internet Options > Advanced (Tab) > CHECK Allow active content to run in files on My Computer (under Security) > OK
That's the simple part out of the way. Now, who can tell me how to place the javascript clock over the header image on the right-hand side of the page ...?
[edited by: JackR at 9:23 pm (utc) on July 21, 2007]
CSS position Property
The position property places an element in a static, relative, absolute or fixed position...