Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 900
  • Last Modified:

using jquery to print a section of a page

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
imageshark
Asked:
imageshark
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
designatedinitializerCommented:
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
imagesharkAuthor Commented:
I found that, and I'm trying it, but I can't seem to get it to work.
0
 
designatedinitializerCommented:
check your browser's error console. What does it say?
0
 
imagesharkAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
imagesharkAuthor Commented:
Solution is working!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now