+ 4

document.write function in java script takes to another screen why

Whenever I use the document.write function to print something it takes me to another screen ,how to prevent that from happening

30th Dec 2016, 6:52 AM
Utkαrsh
Utkαrsh - avatar
5 odpowiedzi
+ 3
Even if you document.write() after the html loaded, it will overwrite it, because it write text directly in the Document object, which contains html ^^ For update you document content without "takes you to another screen" ( clear the content ), you may avoid document.write() use, and use the innerHTML property of html's elements...
30th Dec 2016, 8:33 AM
visph
visph - avatar
+ 3
I don't understand it what do you mean by before the html
30th Dec 2016, 8:45 AM
Utkαrsh
Utkαrsh - avatar
+ 3
thanks
30th Dec 2016, 8:45 AM
Utkαrsh
Utkαrsh - avatar
+ 3
it works when I use it directly but when I use it as a function in a button it prints on another screen
30th Dec 2016, 9:04 AM
Utkαrsh
Utkαrsh - avatar
+ 2
you write the document before the html load, so it overwrites the content
30th Dec 2016, 7:52 AM
Nahuel
Nahuel - avatar