Skip to content

Commit

Permalink
Fixed relative path in link tags
Browse files Browse the repository at this point in the history
relative tags will be converted to absolute path
  • Loading branch information
jihad28 committed May 23, 2022
1 parent 88eef15 commit 9d56866
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions printout.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@
let win = window.open('', ''),
head = '<meta charset="UTF-8"><title>' + config.pageTitle + '</title>';

// Converting style relative path to absolute path and return a corrected link tag
const getLink = (link) => {
let clone = link.cloneNode(true);
clone.href = (new URL(clone.href, location)).href
return clone.outerHTML;
};

// Get all the link tags and append them to the head
if (config.importCSS) {
let links = document.querySelectorAll('link');
for (let i = 0; i < links.length; i++) {
head += links[i].outerHTML;
head += getLink(links[i]);
}
}

Expand Down Expand Up @@ -72,15 +79,10 @@

if (config.autoPrint) {
// Allow stylesheets time to load
const autoPrint = () => {
win.setTimeout(() => {
win.print();
win.close();
}
if (navigator.userAgent.match(/Trident\/\d.\d/)) { // IE needs to call this without a setTimeout
autoPrint();
} else {
win.setTimeout(autoPrint, config.autoPrintDelay);
}
}, config.autoPrintDelay);
}
};
}));

0 comments on commit 9d56866

Please sign in to comment.