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! :-)]

Inspiring
August 8, 2011

Hi, I want to have a link in my webhelp to print the topics including dropdown text. After googling, I found this thread, and did the following to my template:

  1. I added the following script:
  2. <script type="text/javascript" language="JavaScript1.2">//<![CDATA[
    <!--
    var arrayofDivs = document.getElementsByTagName('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>

  3. I added a footer containing:
    <p align="center"><a href="javascrip:void(0);" onclick="window.print()">Click here to print this topic</a></p>
  4. I then added the following to the end of the default.css:

    @media print{

                    div.droptext { display: block !important; }

    }

After I regenerate and open the output in IE8, I click the link and the print dialog appears. It prints as expected/desired, but then the browser shows The webpage cannot be displayed. The address bar shows "javascrip:void(0);" and I have to click Go back to previous page to return to my help.

If I open in Firefox, after printing I get the message "Firefox doesn't know how to open this address, because the protocol (javascrip) isn't associated with any program. [OK]".

Obviously there's an issue with the a href="javascrip:void(0);" section above, but that's what Willam suggested and it apparently worked for Torgeir.

What have I done wrong?