I was looking for a more robust solution, whereby a user (regardless of IT ability) would be able to perform this simple task.
We currently run Learnwise - this has an icon which allows users to print out the contents of the relevant frame. I was hoping that someone had thought of doing this in Moodle.
Not wanting anyone moving to Moodle to miss any cool Learnwise features , here's a hack that adds a print resource link to the navigation bar
e.g. Home >> Test course >> Resource >> Test resource (Print resource)
The print resource link is only added when the content of the frame is an uploaded file, as it's not possible to use javascript when the content comes from a different site.
In mod/resource/type/file/resource.class.php (approx line 374) find
/// If we are in a frameset, just print the top of it
if (!empty($_GET['frameset']) and $_GET['frameset'] == "top") {
Following this line add
$jsstring = "(<a href=\"javascript:if(parent.frames[1].location == 'about:blank') { alert('There is no document to print'); } else { parent.frames[1].focus(); parent.frames[1].print(); }\">Print resource</a>)";
$dodgyjavascripthack = '';
if ($resource->type == 'file') {
//browser security will prevent printing documents from other domains - so we add a couple of simple tests to determine if the link should be displayed
if (strpos($resource->reference, 'http://') === 0) {
$bits = @parse_url($resource->reference);
if (!empty($bits['host']) && $bits['host'] == $_SERVER['HTTP_HOST']) {
$dodgyhackjavascript = $jsstring;
}
} else {
$dodgyhackjavascript = $jsstring;
}
}
and modify the print_header line to be
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name) . ' ' . $dodgyhackjavascript, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
(Thanks to Andy for this code. Please note that it's not been thoroughly tested! )