Want to use code for Print button in topic body

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
gingermc
Propeller Head
Posts: 20
Joined: Wed Oct 11, 2006 10:50 am
Location: Carlsbad, California

Want to use code for Print button in topic body

Post by gingermc »

I like the way the Print button works on the WebHelp toolbar where when you click the Print button, it brings up the Print window.

Can someone tell me how to implement that same functionality in the body of a topic?

My company has a requirement that the Print button be in the topic body, but the code they use brings up a second window that users then have to use Print in the web browser to print.

I'd like to bring up the Print window like Flare does instead, if that's possible.

Here's the code they embed in the topic body for the Print button:

Code: Select all

<a id="wpart1" href="#" onclick="javascript:printTopic();"><img border="0" src="Resources/Images/printable.gif" alt="Printable Version" title="Print this topic" /></a>
Here's the code that's in the JS file they use:

Code: Select all

function printTopic () {
    var path = document.location.pathname
    path = path.substring (path.lastIndexOf ("/")+1) + "#webprint"
	return window.open (path)
}
I've added this code to the \content\SkinSupport\MadCapBody.js file after building the project. It works, but it's not ideal.
Ginger Mc
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: Want to use code for Print button in topic body

Post by NorthEast »

The javascript window.print(); will print the page.

If you want to print the topic without the function to display it in a second window, use:
javascript:window.print();

If you still want it to appear in a second window, use:
javascript:printTopic();window.print();

(If you're still going to use the printTopic script, then instead of inserting it in each topic, I'd suggest keeping it in a js file and adding a link to that file in your master page.)
gingermc
Propeller Head
Posts: 20
Joined: Wed Oct 11, 2006 10:50 am
Location: Carlsbad, California

Re: Want to use code for Print button in topic body

Post by gingermc »

Thanks Dave! javascript:window.print(); does exactly what I need! :D
Ginger Mc
Post Reply