You should enclose your added code in a conditional that determines if the browser can do window.print():
Code:
if(window.print){
var objPrintLink = document.createElement("a");
objPrintLink.setAttribute('href', '#');
objPrintLink.setAttribute('id', 'printLink');
objPrintLink.onclick = function(){window.print(); return false; }
objImageData.appendChild(objPrintLink);
var objPrintIcon = document.createElement("img");
objPrintIcon.setAttribute('src', printIcon);
objPrintIcon.setAttribute('title', 'Print');
objPrintIcon.setAttribute('alt', 'Print');
objPrintLink.appendChild(objPrintIcon);
}
This has nothing to do with your problem, but it will avoid confusion for users whose browser - for whatever reason cannot print using window.print().
I don't see how this:
Code:
Element.setHref('printLink', imageArray[activeImage][0]);
is required at all, but it probably won't hurt anything. The href will never fire. If it did, you would no longer be looking at the page, the image would load by itself into the window.
As to your problem, a link to your page would probably help in diagnosing the issue:
Please post a link to the page on your site that contains the problematic code so we can check it out.
But, are you sure you copied the style exactly as shown earlier in this thread and included the media="print" descriptor for it? What browser are you using?