<div id="c" onClick="func()"></div>
This will execute funct() only when the user will click. But I want to execute func() automatically after 10 seconds. Somethink like this:
<div id="c" After10Seconds="func()"></div>
<div id="c" onClick="func()"></div>
This will execute funct() only when the user will click. But I want to execute func() automatically after 10 seconds. Somethink like this:
<div id="c" After10Seconds="func()"></div>
Write some logic. Use a flag and a timeout
on the page load:
var hasCalledFunc = false;
setTimeout(function() {
if (hasCalledFunc == false) func();
}, 10000);
function callFunc() {
if (hasCalledFunc == false) func();
}
function func() {
hasCalledFunc = true;
//..rest of func
}
And the HTML:
<div id="c" onClick="callFunc()"></div>
Or, all in func
var hasCalledFunc = false;
function func() {
if (hasCalledFunc) return;
else hasCalledFunc = true
//rest of func
}
setTimeout(func, 10000);