Spaces:
Sleeping
Sleeping
Commit
·
67ba65c
1
Parent(s):
cf5c57c
Trying to simplify and open to tab
Browse files- scripts.js +12 -23
- 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 |
-
|
| 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 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
| 153 |
} else {
|
| 154 |
-
console.error('
|
| 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()">
|
| 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">
|