![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,824
Rep Power: 5
![]() |
Compatibility of JS Clock
I have a clock working in IE. I am using a generalised "get_object" function which should be compatible with all standard browsers. However, on FireFox it says that the object doesn't have any properties.
head.js /* GET AN OBJECT */
var objects = new Array();
var type = 0;
if (document.getElementById)
{
type = 1;
}
else if (document.all)
{
type = 2;
}
else if (document.layers)
{
type = 3;
}
function get_object(idname)
{
if (typeof(objects[idname]) == "undefined")
{
if (type == 1)
{
objects[idname] = document.getElementById(idname);
}
else if (type == 2)
{
objects[idname] = document.all[idname];
}
else if (type == 3)
{
objects[idname] = document.layers[idname];
}
}
return objects[idname];
}
/* HIDE/SHOW AN OBJECT */
function hide(contID, imgID, hideurl, showurl)
{
dynobj = get_object(contID)
dynimg = get_object(imgID)
if (dynobj.style.display == "")
{
dynobj.style.display = "none";
dynimg.src = hideurl;
}
else
{
dynobj.style.display = "";
dynimg.src = showurl;
}
return false;
}
/* CLOCK */
clockobj = new Array();
function getclock()
{
for (i=0;i<=5;i++)
{
clockobj[i] = get_object('t'+i);
}
doclock();
}
function doclock()
{
var thetime = new Date();
var parts = new Array();
parts[0] = mk_length(thetime.getHours(), 2);
parts[1] = mk_length(thetime.getMinutes(), 2);
parts[2] = mk_length(thetime.getSeconds(), 2);
for (i=0;i<=2;i++)
{
clockobj[i*2].src = "/images/clock_"+parts[i].substring(0,1)+".png";
clockobj[i*2+1].src = "/images/clock_"+parts[i].substring(1,2)+".png";
}
setTimeout('doclock()',1000);
}
/* GLOBAL */
function mk_length(text, length)
{
text = text + ''
var tlength = text.length;
if (tlength < length)
{
text = '0'*(length-tlength) + text;
}
return text;
}html <img name="t0" alt="Hours" title="Hours" src="/images/clock_0.png" /><img name="t1" alt="Hours" title="Hours" src="/images/clock_0.png" />
<img name="t2" alt="Minutes" title="Minutes" src="/images/clock_0.png" /><img name="t3" alt="Minutes" title="Minutes" src="/images/clock_0.png" />
<img name="t4" alt="Seconds" title="Seconds" src="/images/clock_0.png" /><img name="t5" alt="Seconds" title="Seconds" src="/images/clock_0.png" /> |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 824
Rep Power: 4
![]() |
If you are calling "getElementById", you will need to give your elements an "id" instead of a "name".
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,824
Rep Power: 5
![]() |
OH F#@(*&@#. I can't believe I missed that!
Thanks Dark. I was wondering why it was working everywhere except my clock. Just got to switch name to ID. =} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|