Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    63
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How can I repeat execution of function onclick?

    I'm trying to figure out a click function that would execute a js function twice with, say, a 500 ms delay between each when the user clicks on an <a href>.

    The js function i want to execute twice is document.movie.SetURL - would something like this work?:

    $(document).ready(function () {
    $("a").click(function () {
    document.movie.SetURL;
    delayedClick();
    });
    });
    function delayedClick()
    {
    var t=setTimeout("document.movie.SetURL",500)
    }

    Thanks...

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Did you just come here to ask if your code would work without even testing it once yourself? That's kind of lazy.

    Anyway, regarding the delayed second execution, what you did there is the right idea, but you got a problem in there that will prevent it from working:

    Code:
    document.movie.SetURL;
    is just a reference to the function. You want to execute it, so this line will have to be

    Code:
    document.movie.SetURL();
    Same goes for

    Code:
    var t=setTimeout("document.movie.SetURL",500);
    In order to make it work, you could write it like this:

    Code:
    var t=setTimeout("document.movie.SetURL()",500);
    but this is not recommended. Putting executable code into strings is generally bad style. Rather do it like this:

    Code:
    var t=setTimeout(document.movie.SetURL,500);

  • Users who have thanked venegal for this post:

    piers (07-18-2009)

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    63
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hi venegal, thanks for your response.

    Actually it's not so much that I'm lazy... although I definitely am :]

    I'm trying to address a cross-browser issue that's kinda hard to test for under all circumstances.

    The fix requires a double click by the user, but doesn't result in a dblclick function being executed (if that makes sense) - in other words it's the difference between a physical double click and a programmatical double click. I'm looking to replicate the former...

    and I'm no expert

  • #4
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    I don't quite get what you're talking about there. There's a cross browser issue that's fixed by requiring a double click from the user? That sounds weird. Do you want to simulate a doubleclick? That's easily done by .dblclick().

    If you want help on that, please elaborate.

  • #5
    New Coder
    Join Date
    Jun 2009
    Posts
    63
    Thanks
    8
    Thanked 0 Times in 0 Posts
    yeah - it has to do with FF's optimization - it doesn't instantiate objects that are hidden with display: none

  • #6
    New Coder
    Join Date
    Jun 2009
    Posts
    63
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quick question:

    If document.movie.SetURL() has a variable, which is the url, as in:
    Code:
    document.movie.SetURL(path/mov.mov)
    would the above code work for all the variables when the function is called? I have a bunch of a href's:
    Code:
    <a href="javascript:document.movie.SetURL(mov1.mov);"></a>
    <a href="javascript:document.movie.SetURL(mov2.mov);"></a>
    <a href="javascript:document.movie.SetURL(mov3.mov);"></a>
    etc
    Thanks :]


  •  

    Posting Permissions

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