Reputation: 2803
I have a problem. I'm trying to print out only content which is in a div, basically everything below the buttons (See picture below).
But then i try to print, the result looks something like this:
I.e. without any stylesheets.
But the code includes all the css files I currently have.
This is the function I have. I have tried with or without the stylesheets and different ways to reference them. Can anybody see what I'm doing wrong?
function PrintHistory() {
var printDivCSS5 = new String(
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.core.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.resizable.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.selectable.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.accordion.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.autocomplete.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.button.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.dialog.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.slider.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.tabs.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.datepicker.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.progressbar.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jquery.ui.theme.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jqGrid.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/jqgrid-smoothness-ui.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/datepicker.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/ui.fancytree.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/site.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/bootstrap.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/Hepper.mms.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/bootstrap-select.css">' +
'<link rel="stylesheet" type="text/css" href="http://localhost:62533/Content/themes/base/typeahead.css">');
var oldPage = document.body.innerHTML;
var prtContent = document.getElementById("historyTabeTarget");
var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write("<html><head><title></title></head><body>" + printDivCSS5 + prtContent.innerHTML + "</body>");
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = oldPage;
};
Upvotes: 0
Views: 623
Reputation: 46
I believe it can be achieved by CSS. All you need to do is add the following with the CSS specifications for print in your stylesheet.
@media print{
/* your print css */
}
Use display: none;
for all the elements you do not wish to be printed and override the remaining css accordingly.
Upvotes: 2