printing is not working in chrome browser at first time
win.document.write(htmlContent);
win.document.close();
win.focus();
setTimeout(function(){win.print();win.close();}, 10);
print div in chrome with css not working
the following code work for me fine
<script type="text/javascript">
$(function () {
$("#btnPrint").click(function () {
var contents = $("#table").html();
var frame1 = $('<iframe />');
frame1[0].name = "frame1";
frame1.css({ "position": "absolute", "top": "-1000000px" });
$("body").append(frame1);
var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
frameDoc.document.open();
//Create a new HTML document.
frameDoc.document.write('<html><head><title>DIV Contents</title>');
frameDoc.document.write('</head><body>');
//Append the external CSS file.
frameDoc.document.write('<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />');
frameDoc.document.write('<link href="../dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />');
//Append the DIV contents.
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
window.frames["frame1"].focus();
window.frames["frame1"].print();
frame1.remove();
}, 500);
});
});
</script>
Related Topics
How to Make New Line or Break in Array
Break the Loop of an Array Looping Function (Map, Foreach, etc.)
Random Numbers Between 1 and 50; 50 Times
Javascript Check If Values Exist in Array Json
How to Prevent Ajax Requests to Follow Redirects Using Jquery
Show/Hide Select Options Based on Value of Another Select Using Javascript/Jquery
How to Share and Edit Global Variables Between Two JavaScript Node Runs
Get a Value from a Observable<Value> Object
How to Know If Two Arrays Have the Same Values
Append Data to Json Array Issue
How to Correctly Use Axios Params With Arrays
Get Directory of a File Name in JavaScript
How Could I Get the Latest Date from an Array of Dates - Javascript/Typescript
How to Delete a Query String Parameter in JavaScript
How Add a New Key/Value Pair to a Json Object
Customizing Item-Text in V-Select
Select Li Element With Arrow Keys (Up and Down) Using JavaScript (Jquery)