You cannot use document.write after the page has loaded.