Проблема Chrome с предварительным просмотром - PullRequest
0 голосов
/ 30 октября 2018

Я бы хотел, чтобы при нажатии кнопки для предварительного просмотра страницы. Пока у меня есть следующий код:

  print(resultId){
    var printWindow = window.open('', 'PrintWindow', 'height=800,width=1240');
    printWindow.document.write('<link rel="stylesheet" href="/css/styles.css">');
    printWindow.document.write(document.getElementById(resultId).innerHTML);
    printWindow.document.close();
    printWindow.focus();
    // printWindow.print();
    // printWindow.close();
    // return true;
  }

Это откроет новое окно, но не откроет предварительный просмотр, поэтому в основном вы должны нажать Ctrl + P, а затем нажать кнопку печати в режиме предварительного просмотра.

Если я раскомментирую код с комментариями выше, он откроется непосредственно в режиме предварительного просмотра, но страница в Chrome будет пустой. Есть идеи, почему это происходит? Как мне это исправить?

ОБНОВЛЕНИЕ (пробовал так же, пока пусто):

  print(resultId){
    var printWindow = window.open('', 'PrintWindow', "width="+screen.availWidth+", height="+screen.availHeight);
    printWindow.document.write('<html><head>');
    printWindow.document.write('<link rel="stylesheet" href="/css/styles.css">');
    printWindow.document.write('</head>');
    printWindow.document.write('<body>');
    printWindow.document.write(document.getElementById(resultId).innerHTML);
    printWindow.document.write('</body></html>');
    printWindow.document.close(); // necessary for IE >= 10
    printWindow.focus(); // necessary for IE >= 10*/
    printWindow.print();
    printWindow.close();
    return true;
  }

ОБНОВЛЕНИЕ 2:

 print(resultId){{ 
    var printWindow = window.open('', 'PrintWindow', "width="+screen.availWidth+", height="+screen.availHeight);
    printWindow.document.write('<html><head>');
    // printWindow.document.write('<link rel="stylesheet" href="/css/styles.css">');
    printWindow.document.write('</head>');
    printWindow.document.write('<body>');
    printWindow.document.write(document.getElementById(resultId).innerHTML);
    printWindow.document.write('</body></html>');
    printWindow.document.close(); // necessary for IE >= 10
    printWindow.focus(); // necessary for IE >= 10*/
    printWindow.print();
    printWindow.close();
    return true;
  }

Это откроет Print Priview нормально на Chrome, но без стилизации.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...