Run javascript when topic loads

Explorer ,
Feb 18, 2022 Feb 18, 2022

Copy link to clipboard

Copied

I'm having issues when trying to run javascript on topic pages. I have a script that makes videos responsive but the code will only run once on page load. When navigating between topic pages the code does not run since theres no page load between these.

I've tried inserting the code in the masterpage but still the code won't execute when clikcing between topics. Any ideas?

Views

85

Likes

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
Adobe Community Professional ,
Feb 20, 2022 Feb 20, 2022

Copy link to clipboard

Copied

Which version of Robohelp are you using? If 2019, include whether you're using Classic or New UI. Also, which output and skin are you generating?

Likes

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 ,
Feb 20, 2022 Feb 20, 2022

Copy link to clipboard

Copied

So sorry... I'm using 2020.7.46 with the skin "Orange" as base.

 

Likes

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 ,
Feb 20, 2022 Feb 20, 2022

Copy link to clipboard

Copied

So I've tried adding a simple script in one of the topic like so:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="generator" content="Adobe RoboHelp 2020" />
  <title>Test</title>
</head>
<body>
  <h1>Test</h1>
</body>
</html>
<script type="text/javascript">
  console.log("hello");
</script>

Now the log script will fire when reloading the page but when going from another topic page to this the script won't fire.

Likes

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
Adobe Community Professional ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

If you added the script to only a single topic, then it will only run when you navigate to that topic.

 

I created a test project with Topic A and Topic B. I added the script in Topic A, but just above the closing body tag, because I don't think it would work at all after the html tag.

 

As expected, the script runs when I navigate to Topic A. Also as expected, when I navigate to Topic B, the script doesn't run because it isn't in Topic B. When I navigate back to Topic A, the script runs.

 

If you want the script in multiple topics, I would recommend including the script in a master page. You can then either assign the master page to each topic you want the script in, or assign it in your output preset and the script will be included in all topics.

Likes

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Yes of course, the script would only be run on the specific topic. Either way, it doesn't matter where the script is added, in the masterpage or specific topic, the script will only run when the page is loading which would be once, not when navigating between topics.

Please take a look att my recording of the behavior below.
https://www.screencast.com/t/53EvAWy0b 

Likes

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

So in my video it shows that the log script only fires when I load the page, not when navigating to the topic. If it did it would be multiple of console logs in the console window.

Likes

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

To be clear, the script fires correctly when I'm locally testing with the "view output", this is because the whole project is reloaded when navigating between topics locally. It's when the project is published and on a server that the scripts stops working becasue the whole site is only loaded once you first visit, when navigating topics there's no page load once on the server.

Likes

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
Adobe Community Professional ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

LATEST

I think you'll have to contact support on this one. Use the email address on this page as it goes to Robohelp support staff.https://helpx.adobe.com/contact/enterprise-support.other.html#robohelp

Likes

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