Having an issue with printing a calendar. The problem arises when trying to load CSS with absolute paths like /path/to/css.css
. Opening a window with:
var win = open('', '_blank')
win.document.write(htmlContent)
will display the HTML correctly but won't load the CSS due to incorrect hostname links.
Using a redirect after changing the location isn't a viable solution.
I've managed to achieve the desired outcome with the following function:
function open_calendar(content) {
var win = open(window.location, 'Calendar')
win.addEventListener('load', function () {
win.document.write(content)
})
return win
}
This function opens the window at the same location, then changes the content as needed. However, this method may take some time to load. Is there a cleaner way to achieve the same result?