Solved

using jquery to print a section of a page

Posted on 2012-03-29
8
815 Views
Last Modified: 2012-04-07
Is there a way, using jquery, to print a "section" of a page.

for instance, I have a game schedule in a table. The table is surround by a div called "printarea".

How do I click a printer icon, and the div "printarea" is sent to the printer.
So just the schedule prints, not the entire page, and background, etc...
0
Comment
Question by:imageshark
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37785351
All that normally does is ask the browser to print the page.  What you can do is put the schedule in an iframe and then put the print button in the iframe and print the iframe.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37785355
Or... I have one page where a calendar is included from a separate file.  I have button to open only the calendar in the browser to print it.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37785468
0
 

Author Comment

by:imageshark
ID: 37785476
I found that, and I'm trying it, but I can't seem to get it to work.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37785506
check your browser's error console. What does it say?
0
 

Accepted Solution

by:
imageshark earned 0 total points
ID: 37785657
It was failing on this section of code:

.filter(function(){ // this filter contributed by "mindinquiring"
                    var media = $(this).attr("media");
                    return (media.toLowerCase() == "" || media.toLowerCase() == "print")
                })

It said it couldn't find "media", but I did have a media=print in head section.
I commented out this small section of code in query.printarea.js.
It seems to work now, I tested it in Safari and FF, IE9.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37785802
Here is a simple way to just print the content

function printDiv(id) {
  var html = document.getElementById(id).innerHTML; 
// var html = $("#"+id).html(); // jQuery version
  var w = window.open('','_blank');
  w.document.write('<link href="stylesheet.css" rel="stylesheet"/><body onload="window.focus(); window.print">'+html+'</body>');
  w.document.close();
}

Open in new window

0
 

Author Closing Comment

by:imageshark
ID: 37818699
Solution is working!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell Script need assistance to make some changes 4 58
What is assert.deepEqual? 4 39
Reference Error with plugin 1 30
Error in JQuery 5 35
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now