Solved

Jquery or javascript delay 10 seconds

Posted on 2013-01-17
7
724 Views
Last Modified: 2013-01-17
Hi E's, I have a site that if the client does not nothing, I do launch of a demonstration after 10 seconds.
What I want to know is how I can know if the 10 seconds have passed and launch the function "demo".

The best regards, JC
0
Comment
Question by:Pedro Chagas
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38790059
what do you call nothing?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38790082
Hi @leakim971, I will call the function "function demo()".
In resume, after 10 seconds start the function.

~JC
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38790105
yes but << nothing >> is what for you?

no keypress?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38790143
Oh I see!
I create a game, and if the visitor is the first time that visit my site (for detect that I will use cookies from php), after 10 seconds I launch a demonstration for teach how the game works. The 10 seconds start to count when the page is loaded.
If the visitor wants to stop the demonstration I made available a button for visitor stop see the demo.
That is the base for I need to wait 10 seconds.
I can show you the project: http://rdsrc.us/5J4XG4 (click in the photo to see work the game).

~JC
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38790157
ok so here the logic :
- when starting the game you set a timer to 10s
- if the user do something (click on the button if I well understood) you reset the timer
- if the user lost, you set the timer to 10s

so you need :
var mytimer = setTimeout(function() { demo(); }, 10000);

$(document).ready(function() {
      $("#your_button_id").click(function() {
           clearTimeout(mytimer);
      })
})

function hall_of_fame() { // the function you run when the user loose
       mytimer = setTimeout(function() { demo(); }, 10000);
       // your current code below
}

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38790226
Hi, the function setTimeout is what I need.
No, you don't understand the idea or my explanation not was the best.
In normal sites we don't need demonstrations, but when the subject is a game, and if you never play that game before, you will need help. And that was I will offer to my visitors, with the purpose not lost visitors.
When visitor load the page, if they start to play I not will launch the demo, but if they don't start the game in the first 10 seconds I will launch the demo. Is just that.
Made this experience, go to the project (link in my last post), and tell me if you don't feel lost. If I launch the demo, I increase the probabilities for the visitor don't go out...
So, this line is just what I need for now:
var mytimer = setTimeout(function() { demo(); }, 10000);

The best regards, JC
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38790323
yes, you right, adding a demo is a very good idea, I would prefer to see it from the beggining without waiting the 10s and break it asap the user click somewhere to say << I want to play >>

thanks for the points
have fun dev
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question