Content Script setTimeout()

2,179 views
Skip to first unread message

hexid

unread,
Mar 17, 2010, 11:10:15 PM3/17/10
to Chromium-extensions
I am wondering if I can use setTimeout() to run a function in my
content script...

In this case it is a simple clock, however when I tell it to run a
function it just returns the error "Uncaught ReferenceError:
currentTime is not defined"...

Below is a sample of the code used to execute the clock...


function currentTime(format)
{
current = new Date();
hour = current.getHours();
min = current.getMinutes();
sec = current.getSeconds();

if(min <= 9) { min = '0' + min; }
if(sec <= 9) { sec = '0' + sec; }

if(format == 24)
{
if(hour < 10)
{
hour = '0' + hour;
}
}
else
{
if(hour > 12)
{
hour = hour - 12;
extra = ' PM';
}
else
{
extra = ' AM';
}
if(hour == 12)
{
extra = ' PM';
}
if(hour == 00)
{
hour = '12';
}
if(hour <= 9)
{
hour = '0' + hour;
}
}

$('#time').html('<strong>' + hour + ':' + min + ':' + sec +
((format != 24) ? extra : '') + '</strong>');
setTimeout('currentTime()',1000);
}

if(option.time != 'false')
{
if(option.timeFormat == 24)
{
currentTime('24');
}
else
{
currentTime('12');
}
}


I have tried removing the quotes around 'currentTime()'...except I
just recieve the error "RangeError: Maximum call stack size
exceeded"...

Just hoping I won't have to push the code into the page to execute
it...

Daniel Kantor

unread,
Mar 17, 2010, 11:13:50 PM3/17/10
to hexid, Chromium-extensions
try this - 

 setTimeout(currentTime,1000);


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


hexid

unread,
Mar 17, 2010, 11:18:22 PM3/17/10
to Chromium-extensions
Yep...that got it...

Thanks for the help...

> > To post to this group, send email to chromium-extensi...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

Reply all
Reply to author
Forward
0 new messages