Skip to main content
Inspiring
September 2, 2010
Answered

Javascript for showing/printing dropdown/expanding text - not working in FF

  • September 2, 2010
  • 1 reply
  • 2406 views

Hi


(using RH 8.0.2, building chm/webhelp, displaying webhelp in FF 3.6+)

I've got a clickable text ("Click here to print the topic") in my topic footers which displays dropdowns and expanding texts and opens the print dialog. Works well in IE, but in Firefox nothing happens. Using a Web developer tool to find the error, I get the error message "arrayofDivs is undefined" for the highlighted line in the script below.

I have borrowed the script from the Robohelp experts in this forum, and have no javascript skills, so I'm looking for any clue on how to fix this script for Firefox. Any help is greatly appreciated!

The script:

<script type="text/javascript" language="JavaScript1.2">//<![CDATA[
<!--
var arrayofDivs = document.all.tags("DIV");

function showEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs.style.display = "block"; }
}

function hideEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs.style.display = "none"; }
}
function printEm() { ;showEm();setTimeout('window.print()',50)}
//-->
//]]></script>

The link:

<p align="center"><a href="chap01\#" onclick="JavaScript:printEm()">Click here to print the topic</a></p>

Best regards,

Torgeir

This topic has been closed for replies.
Correct answer Willam van Weelden

Hi,

Replace document.all.tags("DIV") by document.getElementsByTagName('div')

I think that you better show the dropdowns using css. Easier and less code. Amend your link like this:

<p align="center"><a href="javascrip:void(0);” onclick="window.print()">Click here to print the topic</a></p>

In your style sheet, add the following (using an external editor):

@media print{

                div.droptext { display: block !important; }

}

When someone prints, all dropdowns are shown. This doesn’t make any changes to the page, so if the user has dropdowns shown, they won’t be closed.

Greet,

Willam

Message was edited by: W. van Weelden - Email didn't come trough correct.

1 reply

Willam van Weelden
Willam van WeeldenCorrect answer
Inspiring
September 2, 2010

Hi,

Replace document.all.tags("DIV") by document.getElementsByTagName('div')

I think that you better show the dropdowns using css. Easier and less code. Amend your link like this:

<p align="center"><a href="javascrip:void(0);” onclick="window.print()">Click here to print the topic</a></p>

In your style sheet, add the following (using an external editor):

@media print{

                div.droptext { display: block !important; }

}

When someone prints, all dropdowns are shown. This doesn’t make any changes to the page, so if the user has dropdowns shown, they won’t be closed.

Greet,

Willam

Message was edited by: W. van Weelden - Email didn't come trough correct.

TorgeirHAuthor
Inspiring
September 3, 2010

Your suggested fix works fine in both FF and IE. And in the chm :-)

Thanks, Willam! You made my Friday

Best regards,

Torgeir

[EDIT: Willam! sry! :-)]

Peter Grainge
Community Expert
Community Expert
August 8, 2011

I had an error when I tried to update my posting - Firefox seemed to print ok, but didn't include the dropdown content.

In any case, Willam has indicated that that method is outdated.

I wanted to add that I don't care if it's a toolbar button or a link in the topic footer, as long as the user can print with dropdowns.


The wording on my site is

Toolbar Show / Hide / Print including dropdowns / Print as displayed Buttons - Willam van Weelden's new toolbarscripts01.js scripts allow you to add buttons for any or all of the options shown.


See www.grainge.org for RoboHelp and Authoring tips

@petergrainge

Use the menu (bottom right) to mark the Best Answer or Highlight particularly useful replies. Found the answer elsewhere? Share it here.