I am dealing with an old developer site and code.
There is a GLOBAL print function that the guy wrote, which basically feels for any new window that opens (from any method) and "href.match" with the domain name ... the script then applies the print stylesheet if it needs to be and run window.print.
All this is done from a global script that is on every page and contains some other functions.
I am tired of writing cases for every page added that I want to avoid this function. Also, if I write a NOT clause for a specific page, any subsequent page opened in the domain of the child window will then receive this print function. A.
Is there any way to “impose” inheritance in this new window? Basically, to make this window NOT a child of the parent who spawned it?
addEvent(window, 'load', function () {
var printBtn = document.getElementById('print-page');
if (window.opener && window.opener.location.href.match('domainnamehere')) {
var printCSS = document.createElement('link');
var a = document.getElementsByTagName('a');
printCSS.href = 'css/print.css'
printCSS.setAttribute('type', 'text/css');
printCSS.setAttribute('rel', 'stylesheet');
document.getElementsByTagName('head')[0].appendChild(printCSS);
for (var i = 0; i < a.length; i++) {
a[i].href="";
a[i].onclick = function () { return false; };
a[i].style.cursor = "default";
}
window.print();
} else if (printBtn){
printBtn.onclick = function () {
var printWindow = window.open(window.location, 'printwindow', 'resizable,width=800,height=800,scrollbars');
return false;
};
}
});
source
share