User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » javascript firefox compatibility question Page [1]  
quagmire02
All American
44225 Posts
user info
edit post

okay, i have an external javascript file (.js) that creates a binary clock...it looks like this:



<!-- begin

function bClock() {
      if (!document.layers && !document.all) {
      return;
      }
      timePortion = new Array;
      maxLength = new Array;
      var timeGet = new Date();
      timePortion[0] = timeGet.getHours();
      timePortion[1] = timeGet.getMinutes();
      timePortion[2] = timeGet.getSeconds();
      maxLength[0] = 5;
      maxLength[1] = 6;
      maxLength[2] = 6;
      var decimalValue = 0;
      var decimalMod = 0;
      var tempTime = "";
      for (var currentPortion = 0; currentPortion <= 2; currentPortion++) {
            decimalValue = timePortion[currentPortion];
            timePortion[currentPortion] = "";
            while (decimalValue != 0) {
                  decimalMod = decimalValue % 2;
                  decimalValue = Math.floor(decimalValue / 2);
                  timePortion[currentPortion] = decimalMod + timePortion[currentPortion];
            }
            if (timePortion[currentPortion].length < maxLength[currentPortion]) {
                  for (var i = 1; i <= maxLength[currentPortion] - timePortion[currentPortion].length; i++) {
                        tempTime += "0";
                  }
            }
            timePortion[currentPortion] = tempTime + timePortion[currentPortion];
            tempTime = "";
      }
      timeDisplay = '['+timePortion[0]+'|'+timePortion[1]+'|'+timePortion[2]+'] ';
      if (document.layers) {
            document.layers.bclock.document.write(timeDisplay);
            document.layers.bclock.document.close();
      }
      else if (document.all) {
            bclock.innerHTML = timeDisplay;
      }
      setTimeout("bClock()", 1000);
}
window.onload = bClock;

// end -->



i include the file using <script src="bclock.js" language="javascript" type="text/javascript"></script> in the header

wherever i put <span id="bclock"></span> on the page, the binary clock shows up fine...in IE

i realize this is because document.layers and document.all are not standard, while document.getElementById is...i know very little about javascripting (obviously) and while i'm sure i'll get some sarcastic comments concerning the fact that this is a stupid question and i should learn javascript, i was hoping someone could point out to me how i should change the scripting so that it will conform to the standard and therefore show up in firefox

thanks in advance

[Edited on September 13, 2006 at 12:11 PM. Reason : formatting]

9/13/2006 12:06:44 PM

FanatiK
All American
4248 Posts
user info
edit post

haah u n00b, you should learn javascript

9/13/2006 12:16:35 PM

Shaggy
All American
17820 Posts
user info
edit post

If it works in IE then dont worry about it.

9/13/2006 12:16:51 PM

quagmire02
All American
44225 Posts
user info
edit post

^^ see, in all reality, i think learning javascript would be pointless for me as

1.) i am not a web designer by trade, only by hobby
2.) using javascript for ANYTHING other than accenting a site is bad form

i did this code a LONG time ago, when i had the viewpoint of ^

9/13/2006 12:21:42 PM

FanatiK
All American
4248 Posts
user info
edit post

i was just joking... maybe I should learn how to joke.

I don't blame you.

9/13/2006 12:23:08 PM

quagmire02
All American
44225 Posts
user info
edit post

i know you were

but aside from laziness, i really HAVE decided it wouldn't be worth my time...though i did try to google it, which is where i found out about the getElementById thing

9/13/2006 12:25:51 PM

dFshadow
All American
9507 Posts
user info
edit post

Quote :
"If it works in IE then dont worry about it."

for real...

i <3 firefox and all but regular people are retards

9/13/2006 12:26:02 PM

quagmire02
All American
44225 Posts
user info
edit post

but i'm trying to further my knowledge in this small way

9/13/2006 12:41:11 PM

DonMega
Save TWW
4201 Posts
user info
edit post

Quote :
"2.) using javascript for ANYTHING other than accenting a site is bad form"




javascript can totally enhance the UI for a site.

9/13/2006 12:49:48 PM

Stein
All American
19842 Posts
user info
edit post

Quote :
"which is where i found out about the getElementById thing"


Yeah, so use it.

9/13/2006 1:29:03 PM

A Tanzarian
drip drip boom
10995 Posts
user info
edit post

<html>
<head>
<script type="text/JavaScript">

function bClock() {

timePortion = new Array;
maxLength = new Array;
var timeGet = new Date();
timePortion[0] = timeGet.getHours();
timePortion[1] = timeGet.getMinutes();
timePortion[2] = timeGet.getSeconds();
maxLength[0] = 5;
maxLength[1] = 6;
maxLength[2] = 6;
var decimalValue = 0;
var decimalMod = 0;
var tempTime = "";
for (var currentPortion = 0; currentPortion <= 2; currentPortion++) {
decimalValue = timePortion[currentPortion];
timePortion[currentPortion] = "";
while (decimalValue != 0) {
decimalMod = decimalValue % 2;
decimalValue = Math.floor(decimalValue / 2);
timePortion[currentPortion] = decimalMod + timePortion[currentPortion];
}
if (timePortion[currentPortion].length < maxLength[currentPortion]) {
for (var i = 1; i <= maxLength[currentPortion] - timePortion[currentPortion].length; i++) {
tempTime += "0";
}
}
timePortion[currentPortion] = tempTime + timePortion[currentPortion];
tempTime = "";
}
timeDisplay = '['+timePortion[0]+'|'+timePortion[1]+'|'+timePortion[2]+'] ';

document.getElementById("clk").innerHTML = timeDisplay;


}

</script>
</head>
<body onload="window.tmr = setInterval(bClock, 999)" onunload="clearInterval(window.tmr)">
<h1>
<center>
<span ID="clk"></span>
</h1>
</center>
</body>
</html>

9/13/2006 1:32:26 PM

quagmire02
All American
44225 Posts
user info
edit post

^^^ it can indeed enhance it...but relying on javascript as an integral part of your site is dumb...there is a significant percentage of users who block javascripting

^^ i FOUND OUT about it...i couldn't find a sample of how to replace the document.innerHTML with it, though...if you know what i'm looking for, i'd appreciate some guidance

[Edited on September 13, 2006 at 1:47 PM. Reason : .]

9/13/2006 1:34:36 PM

A Tanzarian
drip drip boom
10995 Posts
user info
edit post

I'm not sure what you're talking about, but what I posted (^^) works in Firefox.

9/13/2006 1:46:01 PM

quagmire02
All American
44225 Posts
user info
edit post

sorry...when i replied, your post didn't show up, and i didn't scroll down

replacing



if (document.layers) {
            document.layers.bclock.document.write(timeDisplay);
            document.layers.bclock.document.close();
      }
      else if (document.all) {
            bclock.innerHTML = timeDisplay;
      }



with



document.getElementById("bclock").innerHTML = timeDisplay;



works perfectly...thanks A Tanzarian!

[Edited on September 13, 2006 at 1:55 PM. Reason : .]

9/13/2006 1:47:54 PM

 Message Boards » Tech Talk » javascript firefox compatibility question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.