Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: setInterval & setTimeout in FF

  1. #1
    Join Date
    Aug 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default setInterval & setTimeout in FF

    I can not use setInterval & setTimeout functions in FF? Can everybody help me?

    Thank before

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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

  3. #3
    Join Date
    Aug 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I would suspect that:

    Code:
    var srcElem = getObject(evt); // getObject return a object;
    doesn't. But, as I said:

    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

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It would also be better to pass a function to setTimeout():
    Code:
    function styleOver(evt) {
      var srcElem = getObject(evt);
      timer = setInterval(function() {
        setTimer(srcElem.id);
      }, 1000);
    }
    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.

    Academically, since you should be using the above code anyway, the major problem with this code:
    Code:
    timer = window.setInterval('setTimer(' + srcElem.id + ')', 1000);
    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:
    setTimer(pd)
    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 do
    Code:
    timer = window.setInterval('setTimer("' + srcElem.id + '")', 1000);
    ... but as already explained, you shouldn't.
    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!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    Code:
    timer = window.setInterval('setTimer("' + srcElem.id + '")', 1000);
    That's a very good point, if that were the only problem, then this would also work:

    Code:
    timer = window.setInterval('setTimer(' + srcElem + ')', 1000);
    or, better form:

    Code:
    timer = setInterval(function(){setTimer(srcElem);}, 1000);
    But I suspect that there may be other problems.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's a very good point, if that were the only problem, then this would also work:
    Code:
    timer = window.setInterval('setTimer(' + srcElem + ')', 1000);
    No it wouldn't... if srcElem is an object (presumably an element), then that will render into something like:
    Code:
    setInterval('setTimer([object HTMLDivElement])', 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.
    or, better form:
    Code:
    timer = setInterval(function(){setTimer(srcElem);}, 1000);
    This, however, would pass the srcElem object to setTimer(), which presumably expects a string ID -- thus, my comment on adapting setTimer().
    But I suspect that there may be other problems.
    It's possible. temp304, if none of these ideas solves your problem, we really do need to see more of your code.
    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!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    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.
    I get a little tired of people asking for help and then making it like pulling teeth to get any information about the problem.
    Well, agreed.
    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!

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    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.
    Huh? How? Neither the OP nor myself ever passed it anything other than a string.
    My thinking was that since the argument was obviously passed without delimiters, it must be being treated in the destination function as an object. Not even IE will treat an argument without delimiters as a string.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •