Printing a web page using just url and without opening new window?

You can do this using a hidden iFrame (I’m using jquery for the example):

function loadOtherPage() {

    $("<iframe>")                             // create a new iframe element
        .hide()                               // make it invisible
        .attr("src", "/url/to/page/to/print") // point the iframe to the page you want to print
        .appendTo("body");                    // add iframe to the DOM to cause it to load the page

}

This will load the page you want to print. To print, you can add javascript code to the print page so that it gets printed after loading:

$(document).ready(function () {
    window.print();
});

This will print the page without showing a new window. I’ve tested this in IE8,9 and Google Chrome, so I’m not sure if this works for Safari or Firefox, though.

Leave a Comment