function openWindowAndPrint(context, title = 'Документ') {
const win = window.open();
win.document.write(context);
win.document.title = title;
win.focus(); // Required for IE
ensureImagesLoaded(win.document).then(() => win.print());
win.onafterprint = () => win.close();
return win;
}
function ensureImagesLoaded(document, waitTime = 7000) {
const images = document.querySelectorAll('img');
const loadedList = Array.from(images).map(imageLoadToPromise);
const timeout = new Promise(resolve => setTimeout(resolve, waitTime));
return Promise.race([timeout, Promise.all(loadedList)]);
}
function imageLoadToPromise(img) {
return new Promise(resolve => img.addEventListener('load', resolve));
}
win.onload = () => win.postMessage({
method: 'sendFileData',
payload,
}, '*');
windows.open(). Если вызывать через onclick, проблем с блокировкой окна быть не должно?
_nghost-lli-c18
или _ngcontent-rja-c18
a[_ngcontent-rja-c18] {
color: red;
}
white-space: pre;
const keys = ["name", "my-city-id", "family-status",
"Number", "e-mail"
];
for (let id of keys) {
// выставил
let input = document.getElementById(id);
input.value = localStorage.getItem(id);
console.log("сохранено");
// закинул
let fun = function(id, input) {
input.addEventListener("change", function() {
localStorage.setItem(id, input.value);
});
};
fun(id, input);
}
[
'e-mail',
'family-status',
'my-city-id',
'name',
'Number',
].forEach((id) => {
/** @type {HTMLInputElement} */
const inputElement = document.getElementById(id);
inputElement.value = localStorage.getItem(id);
inputElement.addEventListener(
'change',
() => localStorage.setItem(id, inputElement.value),
);
});