javascript - Document.write only overwrites the page once -



javascript - Document.write only overwrites the page once -

i've been using document.write() replace existing html loaded ajax. if used 1 time per normal load works fine (by normal mean without ajax), if used more once, writes without replacing existing content

in other words, first time document.write() called on page1, page1 overwritten (as intended) next time it's called, new content appended page1. why?

here's code reproduce issue:

global javascript (on pages):

function loadxmldoc(name) { var xmlhttp = new xmlhttprequest(); xmlhttp.addeventlistener("load", transfercomplete, false); xmlhttp.open("get", name, true); xmlhttp.send(); function transfercomplete() { document.write(xmlhttp.responsetext); history.replacestate(null, null, name); } }

page one:

<a href="#" onclick="loadxmldoc('page2.html');">p1</a>

page two:

<a href="#" onclick="loadxmldoc('page3.html');">p1</a>

page three:

<a href="#" onclick="loadxmldoc('page1.html');">p1</a>

that expected behaviour. write method used write content page when rendering.

it replaces page when it's used after page has completed, because first time utilize it, implicit document.open() start new stream write to.

to utilize replace page, phone call document.open first, utilize document.write 1 or more times write content, phone call document.close tell browser new page complete.

javascript html ajax

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -