Try the following:
setTimeout(function() { window.link = true; }, 5000);
This will set the global "link" variable to true after 5 seconds, which will satisfy your if statement.
Edit This may be a little tricky if you're a beginner, but the best way to achieve this is to use a functional area rather than a global area.
In your case, declare the timer function as follows:
var timer = (function () { var link = false; setTimeout(function() { link = true; }, 5000); return function() { alert(link); }; }());
Thus, an anonymous function returns another function, which becomes a timer (), but in this way the timer has access to its "private" variable. For more information, check out Mozilla's article on JavaScript scope.
source share