• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Sep 02, 2010 Sep 02, 2010

Copy link to clipboard

Copied

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

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 02, 2010 Sep 02, 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 cha

...

Votes

Translate

Translate
LEGEND ,
Sep 02, 2010 Sep 02, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 03, 2010 Sep 03, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

Grr, why won't my script show up? Anyway, it's the script Torgeir initially provided above with the change suggested by Willam.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

Hi,

I don't know about the script. I thought it was me.

This method is quite old. Try http://www.wvanweelden.eu/robohelp/scripts/toolbarscripts for a script that works. (It adds buttons in the toolbar.) If you like, I can also create a version you can use in the topics themselves.

Greet,

Willam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

Hi Willam, thanks for the reply. I did come across that procedure from Peter Grainge's site, but I don't use twisties so thought I couldn't use it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

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

Help others by clicking Correct Answer if the question is answered. Found the answer elsewhere? Share it here. "Upvote" is for useful posts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

Yeah, that'll teach me not to skim so fast!

Thanks Willam, everything works perfectly now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

LATEST

Great. I'm glad it works for you.

Greet,

Willam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2011 Aug 08, 2011

Copy link to clipboard

Copied

Hi,

No problem there. As long as you don't use twisties or use the default RoboHelp twisties, the script will work. When you use a custom twisty method, the script probably works, but will not update your twisties.

Greet,

Willam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
RoboHelp Documentation
Download Adobe RoboHelp