drakosfire commited on
Commit
5db29c7
1 Parent(s): 7faae3d

Trying to simplify and open to tab

Browse files
Files changed (2) hide show
  1. scripts.js +12 -23
  2. storeUI.html +1 -1
scripts.js CHANGED
@@ -94,21 +94,8 @@ document.addEventListener("DOMContentLoaded", function() {
94
 
95
  window.printPageContainer = function() {
96
  var pageContainer = document.getElementById('brewRenderer');
97
- if (pageContainer) {
98
- var printWindow = window.open('', 'Print Preview', 'height=800,width=600');
99
- if (!printWindow) {
100
- console.error('Failed to open print window.');
101
- return;
102
- }
103
-
104
- // Introduce a small delay to allow the window to fully instantiate
105
- setTimeout(function() {
106
- if (!printWindow || printWindow.closed || typeof printWindow.closed == 'undefined') {
107
- console.error('Failed to open print window.');
108
- return;
109
- }
110
 
111
- printWindow.document.write(`
112
  <!DOCTYPE html>
113
  <html lang="en">
114
  <head>
@@ -142,16 +129,18 @@ document.addEventListener("DOMContentLoaded", function() {
142
  ${pageContainer.innerHTML}
143
  </body>
144
  </html>
145
- `);
146
- }, 100); // Delay of 100 milliseconds
147
-
148
- // Wait for the content to be fully loaded before printing
149
- printWindow.onload = function() {
150
- printWindow.print();
151
- printWindow.close(); // Close the print window after printing
152
- };
 
 
153
  } else {
154
- console.error('Element with ID "pages" not found.');
155
  }
156
  };
157
 
 
94
 
95
  window.printPageContainer = function() {
96
  var pageContainer = document.getElementById('brewRenderer');
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
+ htmlContent = `
99
  <!DOCTYPE html>
100
  <html lang="en">
101
  <head>
 
129
  ${pageContainer.innerHTML}
130
  </body>
131
  </html>
132
+ `;
133
+ // Open a new tab
134
+ const newTab = window.open('', '_blank');
135
+
136
+ // Check if the new tab was blocked
137
+ if (newTab) {
138
+ // Write the HTML content to the new tab
139
+ newTab.document.open();
140
+ newTab.document.write(htmlContent);
141
+ newTab.document.close();
142
  } else {
143
+ console.error('Failed to open a new tab. It may have been blocked by the browser.');
144
  }
145
  };
146
 
storeUI.html CHANGED
@@ -31,7 +31,7 @@
31
  <button id="submitDescription">Submit</button>
32
  <button id="parseHTML">Parse HTML</button>
33
  <button id="resetButton">Reset</button>
34
- <button onclick="printPageContainer()">Print to PDF</button>
35
  <div class="brewRenderer" id="brewRenderer">
36
 
37
  <div class="pages" id="pages">
 
31
  <button id="submitDescription">Submit</button>
32
  <button id="parseHTML">Parse HTML</button>
33
  <button id="resetButton">Reset</button>
34
+ <button onclick="printPageContainer()">Open Tab to print</button>
35
  <div class="brewRenderer" id="brewRenderer">
36
 
37
  <div class="pages" id="pages">