Solved

Jquery or javascript delay 10 seconds

Posted on 2013-01-17
7
733 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
Suggested Courses

630 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