Trouble inserting Javascript content in Webhelp Responsive Output

Julie P
Posts: 13
Joined: Fri Dec 02, 2016 7:34 pm

Trouble inserting Javascript content in Webhelp Responsive Output

Post by Julie P » Thu Sep 06, 2018 6:10 pm

Hello,

I have trouble inserting a Javascript in my webhelp responsive output. I hope I could get some advice in this forum.

I need to insert a Javascript in the head element of the html pages of my webhelp responsive output. Here is the script:

Code: Select all


<script>if (top.location == self.location) {
top.location = '${oxygen-webhelp-output-dir}/../../documentation.html?' + location.href;
}</script>
This script was created because the webhelp documentation of our company website is contained inside an iframe element, and the script allows to keep the frame when opening a page of the documentation in a new tab/window.

I already have an XML file with an HTML fragment referenced in the webhelp.fragment.head parameter of the transformation scenario (it inserts a link at the top of my pages to come back to the welcome page of the support).

I tried to add the script in this same file, in the body element (also tried in head), according to guidelines in this topic: https://www.oxygenxml.com/doc/versions/ ... ransformat)

So it looks like this:

Code: Select all


<html xmlns="http://www.w3.org/1999/xhtml">
<head xml:lang="en">
<title dir="ltr" lang="en">Back home page</title>
</head>
<body>
<script type="text/javascript">
<!-- if (top.location == self.location) {
top.location = '${oxygen-webhelp-output-dir}/../../documentation.html?' + location.href;
}
-->
</script>
<div class="top_link" style="font-size: 1.1em; color: white; font-family: Roboto;">
<div class="top_link_contents"><a href="${oxygen-webhelp-output-dir}/../index.html"><img src="${oxygen-webhelp-output-dir}/img-fragments/HomePage.png" alt="" width="20"/>
Back to support page</a>
</div> </div>
</body>
</html>
However, it does not seem to work. So I am afraid I did something wrong. I cannot identify if it comes from the HTML fragment itself or from the script. The script does work when manually put in an html topic (for test). Could anyone give me a hand if the issue comes from the fragment?

Thank you,

Julie

alin
Site Admin
Posts: 137
Joined: Thu Dec 24, 2009 11:21 am

Re: Trouble inserting Javascript content in Webhelp Responsive Output

Post by alin » Fri Sep 07, 2018 3:45 pm

Hi Julie,

The problem is that the '${oxygen-webhelp-output-dir}' macro is expanded by the WebHelp plugin only when it is used in an attribute value.
In your case, the macro from the value that is assigned to top.location will not be replaced by the actual path to the output directory.

However, in Oxygen WebHelp 20.1 you can use the new <whc:macro/> template component to expand a macro variable within a text node. You can read more about this component in our User Manual: https://www.oxygenxml.com/doc/versions/ ... gment_file
In this case, your script fragment would look like this:

Code: Select all


<script type="text/javascript">            

var outDirPath = "<whc:macro xmlns:whc="http://www.oxygenxml.com/webhelp/components" value="${path(oxygen-webhelp-output-dir)}"/>";
if (top.location == self.location) {
top.location = outDirPath + '/../../documentation.html?' + location.href;
}

</script>
Note that I have omitted the XML comment surrounding the inline script content in order to have the <whc:macro/> element processed.
The XML comment is mandatory only if your script contains special XML characters (like & or <).

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

Julie P
Posts: 13
Joined: Fri Dec 02, 2016 7:34 pm

Re: Trouble inserting Javascript content in Webhelp Responsive Output

Post by Julie P » Fri Sep 07, 2018 4:55 pm

Hi Alin,

Thank you very much for your help, it works now :D

Best regards,

Julie

Julie P
Posts: 13
Joined: Fri Dec 02, 2016 7:34 pm

Re: Trouble inserting Javascript content in Webhelp Responsive Output

Post by Julie P » Mon Sep 10, 2018 2:52 pm

Hi again,

Actually, I spoke too quickly, there is still an issue… It works for the topic files, but not for the index page, because it is not placed at the same location in the directory as the topics. So the path of top.location is not correct for the index page.
Is it possible to apply this script only to the contents of the topics directory?

Regards,

Julie

Julie P
Posts: 13
Joined: Fri Dec 02, 2016 7:34 pm

Re: Trouble inserting Javascript content in Webhelp Responsive Output

Post by Julie P » Tue Sep 11, 2018 12:44 pm

Ok, I found the solution. I just had to change the script itself by changing the path if the file is index.html.

Post Reply