Solved

Jquery or javascript delay 10 seconds

Posted on 2013-01-17
7
714 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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 …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now