0

Does it have to open in the sam Eg:

function write(){ document.write("write") }

input type="button" onclick="write()" value="Click"

  • I found this question via [Code is disappearing when I type in input element](https://stackoverflow.com/q/54245217/4642212). This is similar code and it wouldn’t work, because the `write()` inside `onclick` calls `document.write` directly, _not_ the custom `write` function. – Sebastian Simon Jan 17 '19 at 22:53

2 Answers2

6

document.write statements must be run before the page finishes loading

EDIT: Therefore, you wouldn't want to put document.write into an onclick

If you're trying to modify a page already loaded you'll have to use div tags and use something like:

document.getElementById("name").innerHTML = "bob";
McAden
  • 13,714
  • 5
  • 37
  • 63
0

No, it doesn't always have to open in a new window.

Now, if you'll be a lot more specific I can give you a better answer.

Welbog
  • 59,154
  • 9
  • 110
  • 123