There is a page with some entries and a check button for each entry. After ticking and clicking on the button, a new page opens, consisting only of the marked entries, which can be saved: RMB - Save as - page.html. How can I make it so that when you click on a button, a new page with marked entries is automatically saved in Page.html?

function make_win(mode,par,waiting){ cmd_str=new Array(); cmd_str[7]= new Array('Печать_записей',cgi+'?I21DBN='+par[0]+'_PRINT&P21DBN='+par[0]+'&S21FMT='+par[1]+'&S21CNR=555&S21COLORTERMS=0&C21COM=S&S21SRW='+par[2]+'&S21ALL='+par[3]+'&FT_PREFIX='+par[6]+'&SAME_SEARCH='+par[4]+'&FT_REQUEST='+par[5]+'&FT_DISTANCE='+par[7]+'&FT_PARAMS='+par[8]+'&FT_NEAR_MFN'+par[9]); x=screen.width-50; y=screen.height-50; cx=screen.width/2-(x/2); cy=screen.height/2-(y/2); adr=(waiting) ? '' : cmd_str[mode][1]; var load_window = window.open(adr,cmd_str[mode][3],cmd_str[mode][4]+',width='+x+',height='+y+',top='+cy+',left='+cx+',resizable=yes,scrollbars=yes'); load_window.focus(); load_window.onload = function() { var html = load_window.document.documentElement.innerHTML; var blob = new Blob([html], {type: "text/html;charset=utf-8"}); window.saveAs(blob, 'print.html'); }; if (load_window == null) { alert('Отключите блокировку всплывающих окон в своём браузере! Всплывающие окна необходимы для корректной работы сайта!'); return; } 
  • Look in the direction of FileApi - Vladimir Klykov

1 answer 1

As an option, use - FileSaver.js

 function save(argument) { var waiting = "ДАННЫЕ"; var html = '<html><body><div style="position: absolute;width:100%; height:100%; z-index:0;" id="progress_bar" ><table style="width:100%; height:100%;"><tr><td align=center><div style="background-color: white"><table style="border: 4px double black; background-color: white"><tr><td align=center ><span style="font-size: 11pt; margin:10px; font-weight:bold">Ждите... '+waiting+'</span><br></td></tr></table></div></td></tr></table></div></body></html>'; //var html = document.documentElement.innerHTML; var blob = new Blob([html], {type: "text/html;charset=utf-8"}); window.saveAs(blob, 'page.html'); } 
 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/FileSaver.js"></script> </head> <body> <h1>What is Lorem Ipsum?</h1> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text <br/>ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived <br/>not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. <br/>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop <br/>publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> <button onclick="save()">Сохранить</button> </body> </html> 

Update 0.0.1 (Save url data)

 var xhr = new XMLHttpRequest(); xhr.open('GET', "https://cors.io/?https://ru.stackoverflow.com", true); // Для примера // xhr.open('GET', "ССЫЛКА", true); xhr.send(); xhr.onreadystatechange = processRequest; function processRequest(e) { if (xhr.readyState == 4 && xhr.status == 200) { return xhr.responseText; }else{ return null; } } function save(argument) { var html = processRequest(); var blob = new Blob([html], {type: "text/html;charset=utf-8"}); window.saveAs(blob, 'page.html'); } 
 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/FileSaver.js"></script> </head> <body> <h1>What is Lorem Ipsum?</h1> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text <br/>ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived <br/>not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. <br/>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop <br/>publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> <button onclick="save()">Сохранить</button> </body> </html> <script type="text/javascript"> </script> 

  • Thank you This is what you need. One question left. There are a number of entries on the page, conditionally, 5. I tick off the needed ones, click on the button, a new page is generated, consisting only of the marked entries. Here you need to download it. How to make it automatically download after generation when you click on the "Download" button? - Nikita
  • Generated using the window.open function ( arguments ). Accordingly, if you write new_window = window.open (), and then to the html: new_window.documentElement.innerHTML variable, then nothing works. If you just throw new.window, then the file will be only "[object Window]". How to deal with this? - Nikita
  • Added to the question. We are talking about working with the database, things like "I21DBN" and so on - the arguments of the emerging links. Actually, there are records that were issued on the search. After you have marked the necessary ones, press the button that creates a new window, in which only the necessary, marked entries. And how to save this window to the document is already a problem - Nikita
  • waiting is not needed, in fact, I'm sorry to have confused. The whole page in cmd_str, with the line "var load_window = window.open (...", in fact, is generated. Everything that is below does not matter , Nikita
  • but I have no specific data. There is an address where you cannot get through documentElement.innerHTML, there is a variable to which windows is written, open, but does not work through it. How to take data if there is only the address of the generated page? Sorry for the stupid questions, quite tight with js-ohm - Nikita