Сохранение web страницы в файл

148
11 февраля 2019, 10:30

Есть страница с некоторыми записям и с check button у каждой записи. После проставления галочек и нажатии на кнопку открывается новая страница, состоящая лишь из отмеченных записей, которую можно сохранить: ПКМ - Сохранить как - page.html. Как можно сделать, чтобы при нажатии на кнопку новая страница с отмеченными записями сохранялась автоматически в 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;
}
Answer 1

Как вариант используйте - 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>

READ ALSO
Размер Landing Page

Размер Landing Page

Сколько должен быть размер лэндинга? у меня оно весит 75мб - это много? слышал что размер лэндинга максимум должен быть 2 мб, а у меня 7

184
В чем может быть проблема выравнивания через row; col?

В чем может быть проблема выравнивания через row; col?

Нужно сделать сеткуПрописал код, но он выравнивает именно вертикально, впритык

176
Как сделать кнопку &#39;Далее&#39;, чтобы она появлялась при определенном количестве слов?

Как сделать кнопку 'Далее', чтобы она появлялась при определенном количестве слов?

Всем приветРебят, у меня вопрос, я задал размеры блоку height: 150; width: 250; Когда человек оставляет комментарий не более 25 слов, необходимо, чтобы...

146
Смена атрибутов

Смена атрибутов

Есть какие-то блоки и какие-то атрибуты, допустим вот так:

157