...

View Full Version : window.print help IE (opening in a new window).



kss17
03-17-2009, 06:45 PM
Hello,

I am trying to open a new window in javascript pointing to a URL and also automatically open the Print dialog (window.print) on the newly opened window. Somehow it works well in Firefox and i see the browser print dialog opened but in IE the print dialog dosent open. I just get the new window in popup.

Here is the code (JSP file) - pageURL and windowId are Java string variables with page URL and window Title of the popup window.




....
<script>
function openPrintWindow(pageURL, windowId) {
var win = window.open(pageURL,windowId,'resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,width= 800,height=600,screenX=10,screenY=10,top=10,left=10');
win.print();
return false;

}
</SCRIPT>
....
<div>
<a href = "#" class="pageToolsAnchor" onclick="return openPrintWindow('<%=pageURL;%>','<%= windowID %>')">
<img id="imgPrint" alt="" src="<%=request.getContextPath()%>/images/icon_print.gif"/>
</a>
</div>


Would appreciate any suggestions.

I should add that I have tried to set the focus on the newly created window..
win.focus() and then
win.print();
Also have tried to reload the window
win.location.reload( false ); and then
win.print();
but they dont seem to work in IE 7. As i said earlier the print dialog appears properly in FF 3.

randomuser773
03-18-2009, 06:19 AM
Hello,

I am trying to open a new window in javascript pointing to a URL and also automatically open the Print dialog (window.print) on the newly opened window. Somehow it works well in Firefox and i see the browser print dialog opened but in IE the print dialog dosent open.Are you trying to print a site on a different domain? If so you'll get an 'access denied' message in I.E.'s (excuse for an) error console.


function openPrintWindow(pageURL, windowId) {
var win = window.open(pageURL,windowId,'resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,width= 800,height=600,screenX=10,screenY=10,top=10,left=10');
try
{
win.print();
}
catch(e)
{
alert('Cross-domain printing initialisation not allowed by this browser\n\nTry Firefox, Safari or Chrome');
}

return false;

}

abduraooft
03-18-2009, 10:28 AM
Can't you just use window.print(); ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum