locked
open print dialog with url data using javascript RRS feed

  • Question

  • User-581279704 posted

     i want to open  print dialog box using javascript which should get content from url to print,the js code which iam trying is as follows

    <script type="text/javascript">
    function openWin(extUrl)
    {

    var myWindow = null;

    var xhr = new XMLHttpRequest();

    xhr.open("GET", extUrl, true);

    xhr.onreadystatechange = function () {

    if (this.readyState === 4 && this.status === 200) { 

    myWindow = window.open('', '', 'width=800,height=800');

    myWindow.document.write(this.responseText);

    myWindow.focus();

    myWindow.print();

    myWindow.close();

    }

    }

    xhr.send();

    }
    </script>

    Wednesday, November 2, 2016 12:35 PM

All replies

  • User347430248 posted

    Hi Jameer,

    please use the code mentioned below.

    <!DOCTYPE html>
    <html>
    <body>
    
    <button onclick="openWin()">Open "myWindow"</button>
    <button onclick="closeWin()">Close "myWindow"</button>
    
    <script>
    var myWindow;
    
    function openWin() {
        myWindow = window.open("", "myWindow", "width=200,height=100");
        myWindow.document.write("<p>This is 'myWindow'</p>");
    myFunction() ;
    }
    
    function closeWin() {
        myWindow.close();
    }
    function myFunction() {
        myWindow.print();
    }
    </script>
    
    </body>
    </html>
    

    Regards

    Deepak

    Thursday, November 3, 2016 2:35 AM