In response to a long-standing user need in the Canvas Community, I cobbled together the code snippet below. This page documents a fully-deployable end-user solution for anybody to test, tweak, and use to produce a plain-vanilla HTML version of a Canvas Quiz, which is printer-friendly from a browser. I share the code below, as well as describe a couple of its limitations.
[for visibility, this document is duplicated as a Discussion in Q & A. There may be versioning discrepancies between them.]
So what is this code?
It's a bookmarklet - a tiny piece of JavaScript you save as a bookmark in your browser, then click to run when you're on the page where you want it to execute.
What does it give me?
A browser window containing the Quiz content in plain HTML. This can be either printed to paper, or saved as a pdf.
How is this useful?
As many have noted in the Idea forum, an easily-printable Quiz meets needs for accommodations and accessibility broadly, as well as students and schools in limited-connectivity or limited-hardware situations, and teachers and administrators in workflow and documentation situations which require hard copy.
Is any admin-level support/installation needed?
No - this code can be deployed by any Canvas user on their own.
Are there any browser-specific caveats?
Edge makes it annoyingly complex to manually create a bookmark(let). I honestly haven't found how to do it. The other browsers (Firefox, Chrome, Safari) are fine with it. I've tested the code in all 3 of these successfully.
Other caveats?
The usual: this is home-grown code, so I make no warranties.
Test before deploying to production. Also, it relies upon the specific element id assigned to Quiz content as of this date - future changes to Canvas production code may break it.
So you mentioned limitations.
- The script grabs the content from the "taking" or "previewing" environment. If you're just viewing the Quiz, you won't get anything.
- The script grabs the Quiz questions that are loaded onto the screen - meaning it's great unless... your Quiz has selected "Show one question at a time".
- There's zero capacity for handling anything to do with question banks, shuffling questions, etc. Straight-up wysiwyg.
How do I deploy and use the code?
- Copy the code below.
- In your browser, create a new bookmark. (In Safari, you'll have to create the bookmark from some random website, then go back and "Edit Address".)
- In the "Location" or "URL" field, paste the code, then save the bookmark.
- Navigate to the Quiz, and click the "Preview" button.
- Once you're previewing the Quiz, click your bookmark, and watch the magic happen.
Can I see it in action?
Sure. Here's a 1-minute video demo.
The code.
javascript<SPAN class="">:</SPAN><SPAN class="">(</SPAN><SPAN class="">function</SPAN> <SPAN class="">printQuiz</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">{</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> document<SPAN class="">.</SPAN><SPAN class="">querySelector</SPAN><SPAN class="">(</SPAN><SPAN class="">"#submit_quiz_form"</SPAN><SPAN class="">)</SPAN><SPAN class="">.</SPAN>outerHTML<SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> document<SPAN class="">.</SPAN><SPAN class="">querySelector</SPAN><SPAN class="">(</SPAN><SPAN class="">".quiz-header"</SPAN><SPAN class="">)</SPAN><SPAN class="">.</SPAN>outerHTML <SPAN class="">+</SPAN> zed<SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> zed<SPAN class="">.</SPAN><SPAN class="">replace</SPAN><SPAN class="">(</SPAN><SPAN class="">/Links to an external site\./gim</SPAN> <SPAN class="">,</SPAN> <SPAN class="">""</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> zed<SPAN class="">.</SPAN><SPAN class="">replace</SPAN><SPAN class="">(</SPAN><SPAN class="">/</SPAN>aria<SPAN class="">-</SPAN>level<SPAN class="">=</SPAN>\<SPAN class="">"2\">/gim , "</SPAN>aria<SPAN class="">-</SPAN>level<SPAN class="">=</SPAN>\<SPAN class="">"2\"><br />"</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> zed<SPAN class="">.</SPAN><SPAN class="">replace</SPAN><SPAN class="">(</SPAN><SPAN class="">/</SPAN><SPAN class="">class</SPAN><SPAN class="">=</SPAN>\<SPAN class="">"screenreader-only\"|class=\"form-actions\"|class=\"accessibility-warning screenreader-only\"|class=\"alert\"/gim , "</SPAN>hidden<SPAN class="">=</SPAN>\<SPAN class="">"hidden\""</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> zed <SPAN class="">=</SPAN> zed<SPAN class="">.</SPAN><SPAN class="">replace</SPAN><SPAN class="">(</SPAN><SPAN class="">/</SPAN><SPAN class="">class</SPAN><SPAN class="">=</SPAN>\<SPAN class="">"answer_input\">/gim, "</SPAN><SPAN class="">class</SPAN><SPAN class="">=</SPAN>\<SPAN class="">"answer_input\" style=\" width: 25px;\">"</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> dt <SPAN class="">=</SPAN> <SPAN class="">new</SPAN> <SPAN class="">Date</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <SPAN class="">var</SPAN> dd <SPAN class="">=</SPAN> dt<SPAN class="">.</SPAN><SPAN class="">getDate</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <SPAN class="">var</SPAN> mm <SPAN class="">=</SPAN> dt<SPAN class="">.</SPAN><SPAN class="">getMonth</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">+</SPAN><SPAN class="">1</SPAN><SPAN class="">;</SPAN> <SPAN class="">var</SPAN> yy <SPAN class="">=</SPAN> dt<SPAN class="">.</SPAN><SPAN class="">getFullYear</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> <BR /><SPAN class="">var</SPAN> myWindow <SPAN class="">=</SPAN> window<SPAN class="">.</SPAN><SPAN class="">open</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN> myWindow<SPAN class="">.</SPAN>document<SPAN class="">.</SPAN><SPAN class="">write</SPAN><SPAN class="">(</SPAN><SPAN class="">"<p>Printer-friendly Quiz generated: "</SPAN> <SPAN class="">+</SPAN> mm <SPAN class="">+</SPAN> <SPAN class="">"/"</SPAN> <SPAN class="">+</SPAN> dd <SPAN class="">+</SPAN> <SPAN class="">"/"</SPAN> <SPAN class="">+</SPAN> yy <SPAN class="">+</SPAN> <SPAN class="">"</p>"</SPAN> <SPAN class="">+</SPAN> zed<SPAN class="">)</SPAN><SPAN class="">;</SPAN> <SPAN class="">}</SPAN><SPAN class="">)</SPAN><SPAN class="">(</SPAN><SPAN class="">)</SPAN><SPAN class="">;</SPAN>
[edit 02/13/2019: added code (courtesy of @MattHanes 🙂 to properly align question answers.]
[edit 01/26/2018: added code to (1) include Quiz instructions; (2) include date printable Quiz was generated; (3) insert space between questions.]
Have fun, and I'd love to hear about how it turns out for you. It goes without saying, but anybody's free to share and tweak at will (for you geeks, I hereby license it under GNU GENERAL PUBLIC LICENSE Version 3. It's also hosted on my github.)
Comments from Instructure
|
With the depreciation of Classic Quizzes in 2024, The Community Team would like to encourage Community Members to explore New Quizzes! Printing is included in the New Quizzes experience: How do I print a quiz in New Quizzes?