I can not use setInterval & setTimeout functions in FF? Can everybody help me?
Thank before
I can not use setInterval & setTimeout functions in FF? Can everybody help me?
Thank before
Please post a link to the page on your site that contains the problematic script so we can check it out.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
function styleOver(evt)
{
var srcElem = getObject(evt); // getObject return a object;
timer = window.setInterval('setTimer(' + srcElem.id + ')', 1000);
}
above function work in IE and Opera, but FF is not. I don't know why?
I would suspect that:
doesn't. But, as I said:Code:var srcElem = getObject(evt); // getObject return a object;
Please post a link to the page on your site that contains the problematic script so we can check it out.
I would at least need to see the setTimer() and getObject() functions to have a clue. There are other minor problems with the code you did present, but these shouldn't cause the problem that you are talking about.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
It would also be better to pass a function to setTimeout():If you're passing an ID, it's likely that you actually want to pass an element to setTimer() but were limited by having to pass a string. If that's so, you should adapt setTimer() to take a direct element reference instead: it's more efficient and cuts down on bulk code.Code:function styleOver(evt) { var srcElem = getObject(evt); timer = setInterval(function() { setTimer(srcElem.id); }, 1000); }
Academically, since you should be using the above code anyway, the major problem with this code:was probably that you forgot to add quotes to the string to be executed by setTimeout(). The final string would have been something like this (if srcElement.id === "pd"):Code:timer = window.setInterval('setTimer(' + srcElem.id + ')', 1000);In Firefox and other non-idiotic browsers, elements are not automatically added to the global scope under their IDs, so this code would fail. It would probably work if you were to doCode:setTimer(pd)... but as already explained, you shouldn't.Code:timer = window.setInterval('setTimer("' + srcElem.id + '")', 1000);
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
That's a very good point, if that were the only problem, then this would also work:
or, better form:Code:timer = window.setInterval('setTimer(' + srcElem + ')', 1000);
But I suspect that there may be other problems.Code:timer = setInterval(function(){setTimer(srcElem);}, 1000);
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
No it wouldn't... if srcElem is an object (presumably an element), then that will render into something like:That's a very good point, if that were the only problem, then this would also work:Code:timer = window.setInterval('setTimer(' + srcElem + ')', 1000);... which makes no sense at all (and is still lacking quotes). This is the biggest limitation of passing a string to setTimeout(): only objects that can be accurately represented as strings can be passed.Code:setInterval('setTimer([object HTMLDivElement])', 1000);This, however, would pass the srcElem object to setTimer(), which presumably expects a string ID -- thus, my comment on adapting setTimer().or, better form:Code:timer = setInterval(function(){setTimer(srcElem);}, 1000);It's possible. temp304, if none of these ideas solves your problem, we really do need to see more of your code.But I suspect that there may be other problems.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Yes, it gets confusing. However, if your original idea Twey, which I think is a good possibility in this case and a good point in general, if that's true, then the setTimer() function is actually expecting an object. Or, perhaps an object and a string. In any event, if that's what is happening, setTimer() is poorly written and I'd need to see it to correct it.
I'd really prefer to see all the code, just in case. That way we wouldn't have to keep going back and asking for more. If it's more code than we need, there is no harm done.
I get a little tired of people asking for help and then making it like pulling teeth to get any information about the problem.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Huh? How? Neither the OP nor myself ever passed it anything other than a string. I was saying it should be rewritten to take an object, not that it already did.However, if your original idea Twey, which I think is a good possibility in this case and a good point in general, if that's true, then the setTimer() function is actually expecting an object.Well, agreed.I get a little tired of people asking for help and then making it like pulling teeth to get any information about the problem.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks