It uses "document.cookie" property to keep state information during page unload/reload.
To test, open this page in Internet Explorer and change the content of the form control. Then, visit Google. When you press the back button, notice the difference between the value of the control when accessed by inline scripts and by the window.onload handler. Apparently, the form values are not restored immediately in Internet Explorer.