Connecting Tech Pros Worldwide Forums | Help | Site Map

Help convert code from IE to Mozilla

Ivan Marsh
Guest
 
Posts: n/a
#1: Jul 23 '05
Hey Folks,

This code works in IE but not in Mozilla. I'd like it to work in both. I'm
sure it has something to do with the way I'm passing the anchor object but
I can't figure it out.


<SCRIPT TYPE='text/JavaScript'>
function GetTime(TimeAnchor) {
today = new Date();
TimeAnchor.innerHTML = today.toLocaleString();
delete today;
}
function UpdateTime(TimeAnchor) {
GetTime(TimeAnchor);
setInterval("GetTime(" + TimeAnchor.name + ")", 1000);
}
</SCRIPT>

<A NAME='DateTime'>
Clock should be here!
</A>

<SCRIPT TYPE='text/JavaScript'>
UpdateTime(DateTime);
</SCRIPT>

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.


ChrisRath
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Help convert code from IE to Mozilla


Internet Explorer plays a bit more loose with the DOM. You can fix the problem
on the invocation by:

UpdateTime(document.getElementById("DateTime"));

[color=blue]
>This code works in IE but not in Mozilla. I'd like it to work in both. I'm
>sure it has something to do with the way I'm passing the anchor object but
>I can't figure it out.
>
>
><SCRIPT TYPE='text/JavaScript'>
> function GetTime(TimeAnchor) {
> today = new Date();
> TimeAnchor.innerHTML = today.toLocaleString();
> delete today;
> }
> function UpdateTime(TimeAnchor) {
> GetTime(TimeAnchor);
> setInterval("GetTime(" + TimeAnchor.name + ")", 1000);
> }
></SCRIPT>
>
>
> Clock should be here!
>
>
><SCRIPT TYPE='text/JavaScript'>
> UpdateTime(DateTime);
></SCRIPT>[/color]

Ivan Marsh
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Help convert code from IE to Mozilla


On Mon, 14 Jun 2004 16:45:07 +0000, ChrisRath wrote:
[color=blue]
> Internet Explorer plays a bit more loose with the DOM. You can fix the
> problem on the invocation by:
>
> UpdateTime(document.getElementById("DateTime"));[/color]

Changing the code to:

<SCRIPT TYPE='text/JavaScript'>
function GetTime(TimeAnchor) {
today = new Date();
TimeAnchor.innerHTML = today.toLocaleString();
delete today;
}
function UpdateTime(TimeAnchor) {
GetTime(TimeAnchor);
setInterval("GetTime(" + TimeAnchor.id + ");", 1000);
}
</SCRIPT>
<A ID="DateTime">
Clock should be here!
</A>
<SCRIPT TYPE='text/JavaScript'>
UpdateTime(document.getElementById("DateTime"));
</SCRIPT>

Updates the anchor with the time initially but the setInterval still
doesn't work in Mozilla.

Any ideas?

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

ChrisRath
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Help convert code from IE to Mozilla


It's the same sort of problem, in that IE exposes the id's at the top level
(which is not part of the DOM standard):

setInterval("GetTime(document.getElementById('" + TimeAnchor.id + "'))", 1000);


Here's the example in entirety:

<html>
<head>
<title>test</title>
<script type='text/JavaScript'>
function GetTime(TimeAnchor) {
today = new Date();
TimeAnchor.innerHTML = today.toLocaleString();
delete today;
}
function UpdateTime(TimeAnchor) {
GetTime(TimeAnchor);
setInterval("GetTime(document.getElementById('" + TimeAnchor.id + "'))",
1000);
}
</script>
</head>
<body>
<span id='DateTime'></span>
<script type='text/JavaScript'>
UpdateTime(document.getElementById("DateTime"));
</script>
</body>
</html>


setInterval("GetTime(document.getElementById('Time Anchor.id + ");", 1000);

[color=blue]
>On Mon, 14 Jun 2004 16:45:07 +0000, ChrisRath wrote:
>[color=green]
>> Internet Explorer plays a bit more loose with the DOM. You can fix the
>> problem on the invocation by:
>>
>> UpdateTime(document.getElementById("DateTime"));[/color]
>
>Changing the code to:
>
><SCRIPT TYPE='text/JavaScript'>
> function GetTime(TimeAnchor) {
> today = new Date();
> TimeAnchor.innerHTML = today.toLocaleString();
> delete today;
> }
> function UpdateTime(TimeAnchor) {
> GetTime(TimeAnchor);
> setInterval("GetTime(" + TimeAnchor.id + ");", 1000);
> }
></SCRIPT>
>
> Clock should be here!
>
><SCRIPT TYPE='text/JavaScript'>
> UpdateTime(document.getElementById("DateTime"));
></SCRIPT>
>
>Updates the anchor with the time initially but the setInterval still
>doesn't work in Mozilla.
>
>Any ideas?[/color]


Ivan Marsh
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Help convert code from IE to Mozilla


On Mon, 14 Jun 2004 18:16:21 +0000, ChrisRath wrote:
[color=blue]
> It's the same sort of problem, in that IE exposes the id's at the top
> level (which is not part of the DOM standard):
>
> setInterval("GetTime(document.getElementById('" + TimeAnchor.id + "'))",
> 1000);
>
>
> Here's the example in entirety:
>
> <html>
> <head>
> <title>test</title>
> <script type='text/JavaScript'>
> function GetTime(TimeAnchor) {
> today = new Date();
> TimeAnchor.innerHTML = today.toLocaleString(); delete today;
> }
> function UpdateTime(TimeAnchor) {
> GetTime(TimeAnchor);
> setInterval("GetTime(document.getElementById('" + TimeAnchor.id +
> "'))",
> 1000);
> }
> </script>
> </head>
> <body>
> <span id='DateTime'></span>
> <script type='text/JavaScript'>
> UpdateTime(document.getElementById("DateTime"));
> </script>
> </body>
> </html>[/color]

That appears to break the setInterval under both browsers... does this run
for you?

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Ivan Marsh
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Help convert code from IE to Mozilla


On Mon, 14 Jun 2004 13:39:01 -0500, Ivan Marsh wrote:
[color=blue]
> That appears to break the setInterval under both browsers... does this run
> for you?[/color]

Scratch that! Had a typo... now it works in both.

Thanks.

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Closed Thread


Similar JavaScript / Ajax / DHTML bytes