iPixel Posted February 10, 2011 Share Posted February 10, 2011 Here's what i'm trying to do. Basically i want to use javascript to check if the user has clicked the mouse button onto a specific link withing a certain amount of time. To make the above clearer i'll give you the scenario... my page loads and only a linked image shows up. While to me it's clearly obvious to think... ok the only thing on the page, let's click it. To others it may not be so obvious, so i want to create an action if a user does not click on the linked image withing let's say 15 seconds after the page has been loaded. Is that possible, if so... what function(s) could i use to achieve this. Thanks to all who help. Quote Link to comment https://forums.phpfreaks.com/topic/227292-need-help-with-an-getting-my-idea-to-work/ Share on other sites More sharing options...
iPixel Posted February 10, 2011 Author Share Posted February 10, 2011 In a more programmatic format... if(15 seconds passed) && (linked image still wasnt clicked) { //do something here } otherwise relax and do nothing. Quote Link to comment https://forums.phpfreaks.com/topic/227292-need-help-with-an-getting-my-idea-to-work/#findComment-1172397 Share on other sites More sharing options...
KevinM1 Posted February 10, 2011 Share Posted February 10, 2011 You could use one of setTimeout() or setInterval(), depending on exactly how you want to go. setTimeout is a one-shot delay, setInterval is a pulse. Quote Link to comment https://forums.phpfreaks.com/topic/227292-need-help-with-an-getting-my-idea-to-work/#findComment-1172408 Share on other sites More sharing options...
iPixel Posted February 10, 2011 Author Share Posted February 10, 2011 what i managed so far is to start a counter once page loads and at 15 seconds execute a function. now however, i need to figure out how to stop that function from executing if the image is clicked before the 15 second interval. Quote Link to comment https://forums.phpfreaks.com/topic/227292-need-help-with-an-getting-my-idea-to-work/#findComment-1172415 Share on other sites More sharing options...
iPixel Posted February 10, 2011 Author Share Posted February 10, 2011 Ok i figured it out... Here's how for the curious ones. I started a counter, so for ever 1 second i increased the variable C by 1. var c=0; var t; function timedCount() { if(c == 5) { $('#reminder').delay(100).fadeIn('slow'); $('#reminder').delay(100).fadeOut('slow'); return; } c=c+1; t=setTimeout("timedCount()",1000); } at 5 seconds something happens, and to stop it.. onClick the image clears the time counter with clearTimeout(t); effectively stopping the function's if statement from ever occuring as long as it's before the 5 second mark. Quote Link to comment https://forums.phpfreaks.com/topic/227292-need-help-with-an-getting-my-idea-to-work/#findComment-1172430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.