Solved

using jquery to print a section of a page

Posted on 2012-03-29
8
857 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a script that will create its own directory to dump logs into 7 50
NOT having JQuery DataTable Columns Sort 7 35
Driver collector? 4 38
Check for Numeric Phone Field 14 47
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

734 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