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

Possible to use custom JavaScript in master pages?

New Here ,
Jun 29, 2009 Jun 29, 2009

Copy link to clipboard

Copied

Hello all,

I'm working on a WebHelp project using RH8. I'm trying to insert some JavaScript code into a master page so that the script will apply to all help topics that use the master page, but I'm running into problems.

To add the code, I'm opening the master page and switching to RH's HTML Editor. Form there, I'm pasting the code into the proper locations as described by my developers:

  • onload="getData()"
    (Inserted inside the opening BODY tag)
  • <script type="text/javascript" src="script.js"></script>
    (Inserted between the HEAD tags)

The problem occurs when I generate the WebHelp layout. When I view the source of the generated topics, the lines I inserted are nowhere to be found. RoboHelp seems to be deleting them.

Am I doing something wrong? Or is it just not possible to use master pages in this way? If anyone has any ideas, I'd appreciate your input.

I realize I can accomplish this using a search-and-replace operation on the generated help topics. But for various reasons, I'd rather find a way to do this using the master page if possible.

Thanks!

Views

1.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
Community Expert ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

Could it be that the path to script.js needs to be amended? If that file is in the root of your project and the topics are in folders, the relative path will be wrong so maybe RH is stripping it out because it cannot see that file. Also is it included in the baggage?


See www.grainge.org for RoboHelp and Authoring tips

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
New Here ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

Peter,

Thanks for your reply. To answer your question, the scripts.js file is in the same directory as the topics, and I did add it as a baggage file.

I suspect that the location of the .js file is not the issue, though, because I also tried inserting the script in its entirety. In other words, instead of referencing a .js file with the src attribute, I placed the full script between <script> tags and inserted it between the <head> tags, like so:

<head>

     <script language="javascript" type="text/javascript">

          [full text of script]

     </script>

</head>

Unfortunately, the result was the same: In the rendered topic, the script is nowhere to be found.

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 ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

Hi there

This is going to somewhat depend on how you are using Master Pages. Keep in mind they may be used in two different ways.

Using them in way number one, you apply something such as a Header, Footer or Placeholder across existing topics.

Using them in way number two, you define the page as you want it to initially look. Perhaps a certain image inside a table and other basic things. Then you create totally new topics that use what you set up as a foundation.

If you attempted to insert the code in the Master Page *THEN* apply it to existing content, it's likely not going to work for you. But it may work for the second method I proposed.

Cheers... Rick

Helpful and Handy Links

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
New Here ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

Rick,

I think you nailed it. Thanks very much.

When I create new topics based on my master page, my custom script code is retained. If I try to apply the master page to existing topics, that's when the problems occur.

I had no idea there was a difference between using master pages to create new topics vs. applying master pages to existing topics, I'm not quite sure I understand why the behavior is different, but I can see that it is.

In any case, I'm left with a parting question:

If I want to my custom script to work with existing topics using the master page method, will I need to create new topics (based on my master page) and then copy/paste the body contents of the existing topics into those new topics? Or is there another, less painful method? 🙂

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 ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

LATEST

Hi there

You might try inserting the code in a Footer or a Header that is linked to a Master Page. If you have a Footer or Header linked to a Master Page you may apply the Master Page to all your topics and they will propagate accordingly. (And hopefully carry the script along)

The only real issue with this is if you have a link to the JavaScript file that is relative (../Myfile.JS).

This is because when the Master Page is applied to the Topics, the link isn't amended properly to include different folder levels.

Cheers... Rick

Helpful and Handy Links

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