XMLHttpRequest response to open new page? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- epergola · 2020-05-10 19:36 I can't get past this. I have a synapse http server. The client side sends a request, the app (server) creates an html which is saved to the outputdata stream that is sent back to the client. This updates the on the client side. As long as I am on the same client html page everything works fine. But for one client request I need to open a  a new page. And here I get stuck. Previously I add this script to the client Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   var xhr = new XMLHttpRequest;  xhr.onreadystatechange=function(){    if (xhr.readyState === 4 && xhr.status ===200) {   (normally, document.body.insertAdjacentHTML("beforeend", xhr.responseText);');      what should I do here for this different purpose?    }  }  xhr.open("POST","http://192.168.1.64",true);  xhr.setRequestHeader("Content-Type", "text/xml");    xhr.send(); Normally I have this in the request processing on the server side Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    l:=loadheadings(t);   l.SaveToStream(OutputData);    ..... set all appropriate headers and send them  Sock.SendBuffer(OutputData.Memory, OutputData.Size); The page gets updated according to the L (which is html markup). But i I want to load a new page loaded with this L, and open it, what should I do? Perhaps save L to a disk file in the server side? What should go in the xhr.onreadystatechange=function() and what should I return after loadheadings() on the server side? ---------------------------------------------------------------------- fjabouley · 2020-05-10 20:41 . ---------------------------------------------------------------------- fjabouley · 2020-05-10 20:56 Argh editing posts is horrible.... Can you send xml from server to change innerhtml code in your client page? ---------------------------------------------------------------------- epergola · 2020-05-10 23:05 Thanks. Yes, but in this particular case I want to leave the current page as is, and open a new page with the html created in the response ---------------------------------------------------------------------- kupferstecher · 2020-05-10 23:21 You could call a new address in the code. https://stackoverflow.com/questions/2018567/loading-another-html-page- from-javascript (I'm not proficient in that field, there are probably better solutions.) ---------------------------------------------------------------------- fjabouley · 2020-05-11 05:09 Maybe this? Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  var xhr = new XMLHttpRequest;    xhr.onreadystatechange=function(){    if (xhr.readyState === 4 && xhr.status ===200) {var new_window = window.open(null, '','_blank');new_window.document.write(xhr.responseText);    }  }  xhr.open("POST","http://192.168.1.64",true);  xhr.setRequestHeader("Content-Type", "text/xml");  xhr.send();    Remove "_blank" to open in other tab, instead of opening in a new window. Regards ---------------------------------------------------------------------- epergola · 2020-05-12 17:54 Thanks fjabouley. That works, but the script inside the new windows (like onclick() function) do no execute.