TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Print Popup in JavaScript
Abhishek Chadha
Jun 09
2016
Code
2.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
var contents = $(
"#orderdetail"
).html();
// get the content to print
var frame1 = $(
'<iframe />'
);
frame1[0].name =
"frame1"
;
$(
"body"
).append(frame1);
var framePrint = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
framePrint.document.open();
//Create a new HTML document.
framePrint.document.write(
'<html><head><title>DIV Contents</title>'
);
framePrint.document.write(
'<link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />'
);
framePrint.document.write(
'<link href="assets/css/print.css" rel="stylesheet" media="print" type="text/css" />'
);
// class and styles used in content to print
framePrint.document.write(
'</head><body>'
);
//Append the external CSS file.
//Append the DIV contents.
framePrint.document.write(contents);
framePrint.document.write(
'</body></html>'
);
framePrint.document.close();
setTimeout(function()
{
window.frames[
"frame1"
].focus();
window.frames[
"frame1"
].print();
frame1.remove();
}, 500);
Print Popup
JavaScript