locked
Chrome browser becomes non responsive while executing window.print() RRS feed

  • Question

  • Hi All,

    As silverlight printing is pretty slow when Non POS Printer is selected, As a alternate we are printing using javascript.  Silverlight application passes content to be printed to javascript. In Javascript i am writing whole content into a window and call window.print(). 

    Silverlight code:

    string template = "<table style=\"width:600px;\"><tr><td>Test1</td><td>Test2</td><td>Test3</td></tr><tr><td>Test4</td><td>Test5</td><td>Test6</td></tr></table>";
    
    HtmlPage.Window.Invoke("TestPrint", template);

    Javascript code:

    function TestPrint(strParamGGS) {
                   var w1 = window.open("", "", "width=600, height=400");
                   w1.document.write(strParamGGS);
                    w1.document.close();
                    w1.focus();
                    w1.print();
                    w1.close();
            }

    The above code works fine in IE,firefox but in Chrome (version  43.0.2357.124) when w1.Print(); is called, UI hangs out and print preview window is also not displayed. 

    The above javascript code works fine in chrome when called from HTML button click.

    Please let me know how to fix the above issue.

    Monday, June 15, 2015 8:25 PM

Answers

All replies

  • Hi RaghuK,

    Please verify whether your Chrome browser enable Silverlight plug-in? In April 2015 NPAPI support have been disabled by default in Chrome and in September 2015 NPAPI will be permanently removed from Chrome, which you could read from this blog . I suggest you run your Silverlight application with IE or Firefox.
    Please copy https://www.microsoft.com/getsilverlight/Get-Started/Install/Default.aspx to Chrome address bar, if you get this message : "You are running on a browser that may not be fully compatible with Microsoft Silverlight.", it means the NPAPI is disabled by Chrome. Please enable NPAPI as follow steps:
     1) Type "chrome://flags/#enable-npapi " in the address bar
     2) Find the "Enable NPAPI"
     3) Click "Enable"
     4) Restart Chrome

    Best Regards,
    Weiwei

    Tuesday, June 16, 2015 8:36 AM
    Moderator
  • I would have thought he/she might have noticed if Silverlight wasn't there at all in order to click the button/whatever and initiate the process.

    But... there is now 3 months before Google push out a version of Chrome which won't allow Silverlight to work at all.

    I would have thought that means it's a bit academic how slow Chrome is and time to change to a different browser.

    Or convert the whole thing to asp.net.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Tuesday, June 16, 2015 8:43 AM
  • Hi RaghuK,

    I will mark Andy's post as answer, if this doesn't give you any help, please feel free to let me know and follow up.

    Best Regards,
    Weiwei

    Thursday, June 25, 2015 2:24 AM
    Moderator
  • Hi Andy,

    Thanks for the suggestion. But this is not a solution for the problem.

    Regards,

    Raghu

    Thursday, June 25, 2015 7:28 PM
  • Hi RaghuK,

    Your issue is caused by the window.close(). Please try to close the print window manually.

    function printPage(){
        window.print();
        /*
         * wait 10 seconds before window.close()
         */
        setTimeout(function(){
            window.close();
        }, 10000); 
    }
    

    If it doesn't work, please refer following thread that similar with your problem.

    http://forums.asp.net/t/1657036.aspx?window+print+does+not+work+in+google+chrome

    If you have solved, please share your solution with other commities. Thank you.

    Best Regards,
    Weiwei

    Friday, June 26, 2015 1:47 AM
    Moderator