var win = window.open(), i = 0; win.document.write(i); win.document.onkeydown = function () { win.document.write(++i); };