Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using jquery to print a section of a page

Posted on 2012-03-29
8
Medium Priority
?
890 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 84

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 84

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

604 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