Search code examples
javascriptjqueryjquery-mobiletiming

Execute JqueryMobile Popup on Jquery timing event


I am having trouble attaching a timing event to my function I want this to on execute the function after 25 seconds. what am I doing wrong?

    setTimeout("ajaxTimeout();", 25000);

        $(document).on({

//open popup here
'pageshow': function ajaxTimeout(){
    $('#askforsomething').popup('open');
}
}, '#homepage');

Solution

  • Two points:

    1. You probably mean $(document).ready(function () { ... }). Alternatively, a shorthand for this is simply $(function () { ... }).
    2. You can (and should) pass a function to setTimeout instead of a code string.

    Result:

    $(function () {
    
      setTimeout(function () {
        $('#askforsomething').popup('open');
      }, 25000);
    
    });