Skip to content Skip to sidebar Skip to footer

SetTimeOut On Alert Box

Thanks for every bit of help that you have all rendered in this forum. On behalf of others, I am grateful and want to make you understand that. Meanwhile, there is this quest that

Solution 1:

You can't time out an alert. It's a low-level JavaScript construct that creates a native application dialog that needs to be confirmed by the user before it gets destroyed. If you want to "throw up data" to the user, you'll have to use an actual HTML dialog library (or roll your own).

Also, don't use alert(). It was great when we had no alternative, but these days you use console.log(...) to simply log data (any data. numbers and strings, but also entire objects and HTML elements!) to the dev tools console (every browser comes with one baked in), and there are a million and one JS libraries that will generate nice looking modals for users instead (the only legitimate use of an alert these days is to force a halt on the entire page processing thread... And off the top of my head I can't think of a single reason why you'd want to do that).

That said, the PHP code you gave makes absolute no sense at all. It's literally a .js file, with a .php extension. Remove those php tags, save it as .js, and just <script src="thatfile.js"></script> that thing. Don't make PHP do things that you don't need PHP for in the slightest.


Solution 2:

is it not possible to do:

var t = setTimeOut(function(){
alert("Your score is: ". $score. '.");
},5000); //5secs

?


Post a Comment for "SetTimeOut On Alert Box"