scala> for(x <- List(1,2,3,4)) println(x + 1)
2
3
4
5
You will likely want to use the "onbeforeunload" event too, it provides more control than the "onunload" event.
That said, be aware that: Opera doesn’t fire the unload event when the browser refreshes the page, or uses the back/forward buttons to browse off of the page. What’s worse, Opera never fires the onbeforeunload event. Thus if you are supporting Opera - be aware of these issues.
Не при всех обстоятельствах нет. Браузер может дать сбой и т. Д., Не давая событию сработать. Пользователь также может использовать надстройки, такие как Grease Monkey, чтобы предотвратить запуск события.