Is there any way to print a div using knockout, durandal and html 5?
I am using knockoutjs and durandal to build my application in HTML 5. I am trying to print a div. I am using the following code
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;
/Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
<input type="button" value="Print 1st Div"
data-bind="function(){printDiv('printablediv')}" />
The div is getting printed but after that I am kind of losing the context of my page. I am clicking on the page but nothing is happening.