Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.print help IE (opening in a new window).

    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.


    Code:
    ....
    <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.
    Last edited by kss17; 03-17-2009 at 06:59 PM.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by kss17 View Post
    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.

    Code:
    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;
    	
    }

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Can't you just use window.print(); ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •