dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: can setTimeout() call other function within a function? or a local object's sub-func?

  1. #1
    Join Date
    Jan 2006
    Posts
    3

    can setTimeout() call other function within a function? or a local object's sub-func?

    hi,

    see, i popup a page and simply close it immediately:

    HTML Code:
    function doPost() {
        var bump = window.open('some.html','');
        bump.close();
        return false;
    }
    which works with no aim.. now i want to do it again with delay which means setTimeout() !!

    HTML Code:
    function doPost() {
        var bump = window.open('some.html','');
        setTimeout("bump.close()", 3000);
        return false;
    }
    result is Reference to undefined variable : bump because bump is not global. well i cant either make it another function and call by setTimeout() which is already in a function..

    any idea ? tnx

    popup page is NOT editable so no onLoad="" as well...

    who the dummy designed that setTimeout() function, idiot JS core developer !!

  2. #2
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    Just put this statement outside the function

    var bump = window.open('some.html','');


    Then it'll be global and you can call the close() method

  3. #3
    Join Date
    Jan 2006
    Posts
    3
    but then bump window will be opened instantly the page loads which i dont prefer. I want to call it within the function launchs. like some form's onSubmit
    and another fix solition is put it out of function as you said and close it right again which is not professional...

    tnx anyway.

  4. #4
    Join Date
    Jan 2006
    Posts
    3
    Well thanks a lot JPnyc !

    I got the idea like ;
    HTML Code:
    var bump;
    function doPost() {
        bump = window.open('some.html','');
        setTimeout("bump.close()", 3000);
        return false;
    }
    I only define bump outside the function.. and assign the window.open to global var without re-defining...

    so it becomes gloabal as well as called within the function. Can be closed by setTimeout() too...

    thanks a lot for the IDEA buddy !!

  5. #5
    Join Date
    Aug 2005
    Posts
    66
    You should try to avoid using popups as some systems and newer systems which are upto date with latest patches will block popups. Most firewalls will also block pop-ups, cookies and other methods of delivery of advertising.

    IF you must advertise, your better off delivering banners to your web site page that rotate or change with eash page click, etc.

    Using .setTimeout() for a task that is going to repeat, use the .setInterval() as this only needs setting once and if you use currentID=window.setInterval(myfunc,60000); will setup a reference to the event, this can be used to stop the interval with clearInterval(currentID); so you can call a routine and it will be called (in this case every 60 seconds) every 60000 milliseconds.

    I built a banner script that used a system of set & clearInterval to alter the display length of the images so that slideshows can be made up where several images can be played at varying rates or held for as log as required.

    clearInterval: http://msdn.microsoft.com/workshop/a...arinterval.asp
    setInterval: http://msdn.microsoft.com/library/de...etinterval.asp

    of course, if IM barking up the wrong tree, ignor me ;o)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles