" JCO" <J.Oliviero@ver izon.net> wrote in message
news:ZWjWb.4514 $1B6.1419@nwrdd c03.gnilink.net ...[color=blue]
> How do you do this. I would like for it to be as dynamic as each page
> refresh.
> Thanks[/color]
Will this help? Test as-is; watch for word-wrap.
<html>
<head>
<title>time.htm </title>
</head>
<body>
<script type="text/javascript">
document.write( '<span id="clock"></span>');
isNS4 = (document.layer s) ? true : false;
isIE4 = (document.all && !document.getEl ementById) ? true : false;
isIE5 = (document.all && document.getEle mentById) ? true : false;
isNS6 = (!document.all && document.getEle mentById) ? true : false;
var clock = "";
if (isNS4) {
clock = document.layers["clock"];
} else if (isIE4) {
clock = document.all["clock"];
} else if (isIE5 || isNS6) {
clock = document.getEle mentById("clock ");
}
function clockTick() {
var Now = new Date();
var Nhh = Now.getHours();
var Nnn = Now.getMinutes( );
if (Nnn < 10) Nnn = "0" + Nnn;
var Nss = Now.getSeconds( );
if (Nss < 10) Nss = "0" + Nss;
var Nap = "AM";
if (Nhh >= 12) {
Nhh -= 12;
Nap = "PM";
}
if (Nhh == 0) Nhh = 12;
var Str = new Array();
Str[0] = "<font color='#000000' >";
Str[9] = Nhh;
Str[10] = ":";
Str[11] = Nnn;
Str[12] = ":";
Str[13] = Nss;
Str[14] = " ";
Str[15] = Nap;
Str[16] = "</font> ";
var Clock = Str.join("");
clock.innerHTML = Clock;
}
setInterval("cl ockTick()",1000 );
</script>
</body>
</html>
McKirahan wrote:
[color=blue]
> " JCO" <J.Oliviero@ver izon.net> wrote in message
> news:ZWjWb.4514 $1B6.1419@nwrdd c03.gnilink.net ...
>[color=green]
>>How do you do this. I would like for it to be as dynamic as each page
>>refresh.
>>Thanks[/color]
>
>
>
> Will this help? Test as-is; watch for word-wrap.
>
> <html>
> <head>
> <title>time.htm </title>
> </head>
> <body>
> <script type="text/javascript">
> document.write( '<span id="clock"></span>');
> isNS4 = (document.layer s) ? true : false;
> isIE4 = (document.all && !document.getEl ementById) ? true : false;[/color]
IE4 is not the only browser that can pass that test.
[color=blue]
> isIE5 = (document.all && document.getEle mentById) ? true : false;[/color]
IE5+ is not the only browser that can pass that test.
[color=blue]
> isNS6 = (!document.all && document.getEle mentById) ? true : false;[/color]
And NS6 is definitely not the only browser that passes that test.
[color=blue]
> P.S. I'm sure someone will "refine" it![/color]
Doubtful. Discredit it maybe.
Consult the FAQ with regards to dynamically changing page content, it
has its own section. As written, your code will utterly fail in NN4.xx
as it doesn't support innerHTML in any fashion.
"McKirahan" <News@McKirahan .com> wrote in message
news:%qqWb.5841 $_44.9944@attbi _s52...[color=blue][color=green][color=darkred]
>>>P.S. I'm sure someone will "refine" it![/color]
>>
>>Doubtful. Discredit it maybe.[/color]
>
>You would have helped the OP if you had refined the solution
>offered rather than just discrediting it.[/color]
It wasn't necessarily Randy's intention to help the OP. This isn't,
after all, a help desk, it is a discussion forum. OPs actually getting
help is just a pleasant side effect of that.
The real benefit in the group goes to the regular participants, who you
appear to have decided to join. And to receive that benefit you will
have to be willing to be criticised because if nobody tells you when you
are wrong you will never know how or what you can improve. And then, if
you don't believe that you are not wrong, you can always argue your
case. Though not in this instance as the object inference style of
scripting is completely discredited.
Thinking back to when I started positing in this group, I thought I
understood javascript fairly well. I was very wrong but I needed some
hindsight to appreciate that, and people pointing out where and why I
was wrong. I also needed to react by taking what I was being told on
board and going away and re-doing and re-posting the scripts that had
been criticised until they were right. I learnt a great deal doing that,
more than I had expected was possible.
If you reacted to Randy's comments by identifying what is wrong with
your object inference script and replaced it with a feature detecting
equivalent and posted that you would probably learn something useful
along the way, and the OP would then also benefit. (Though I think your
code is well outside the rather inadequate spec originally posted.)
- and may eventually be joined by a page on W3C DOM methods, which you
could investigate in this context as you would only be sacrificing
support for IE 4 if you used those. (Specifically, re-setting the
nodeValue property of the text node within the SPAN element as that is a
lot more efficient than re-writing its innerHTML).
McKirahan wrote:[color=blue]
> "Randy Webb" <hikksnotathome @aol.com> wrote in message
> news:6bqdnQOOFv TXubfdRVn-vA@comcast.com. ..
>[color=green]
>>McKirahan wrote:
>>[color=darkred]
>>>P.S. I'm sure someone will "refine" it![/color]
>>
>>Doubtful. Discredit it maybe.[/color]
>
>
>
> You would have helped the OP if you had refined the solution offered rather
> than just discrediting it.[/color]
The only way to "refine" that script is to discard it and start over.
The reference to the FAQ (and reading it) will do both of you way more
good than me writing a clock script will ever do.
Just for kicks and giggles, you can look at <URL: http://www.hikksworld.com/clock.html /> though. Its one I made a while
back that has some other things on it, but the clock is there.
JRS: In article <e4kWb.2985$jk2 .14236@attbi_s5 3>, seen in
news:comp.lang. javascript, McKirahan <News@McKirahan .com> posted at Wed,
11 Feb 2004 06:36:58 :-[color=blue]
>" JCO" <J.Oliviero@ver izon.net> wrote in message
>news:ZWjWb.451 4$1B6.1419@nwrd dc03.gnilink.ne t...[/color]
[color=blue][color=green]
>> How do you do this. I would like for it to be as dynamic as each page
>> refresh.[/color][/color]
[color=blue]
>isNS4 = (document.layer s) ? true : false;[/color]
You cannot identify browsers in that manner. To some extent, you can
determine the nature of a browser : what it is-or-resembles. To reflect
this, change "isNS4" to "asNS4", etc. But read RC's FAQ notes.
setInterval(... , 1000) does not fire once per second, in at least some
systems. Read the FAQ.
The OP asked for the time to be shown at each page refresh, not
continuously. A mere document.write( new Date()) will do that.
The following can be used for converting proper hours to Merkin ones :
Nap = ["AM","PM"][+(Nhh>11)]
Nhh = 1 + (Nhh+11)%12
Partially tested.
Comment