I am experimenting with JavaScript again, and wanted to make a clock in an alert box (bookmarklet).
The following code:
javascript:alert(new%20Date().toLocaleString())
will show the time in the format Wednesday, August 08, 2012 12:40:54 AM. However, the time for the clock is not updated because the bookmarklet is just fetching the time. So, are alert boxes able to be updated (like this:)
javascript:alert(setInterval("new%20Date().toLocaleString()",1000))
or is an alert box not able to be updated (it fetches something and then stops executing script)?
EDIT* I have tried the second code line already and know it doesn’t work, I only mean for it to be an example of finding a method that allows the time to be updated.
No – alert boxes print a string and their content cannot be changed whilst they are showing.
Use a DHTML dialog simulation instead, such as Facebook’s. Since these are just HTML doing the job of native modal functions (e.g.
alert()) they are much more flexible.