Flare 2020 R2 - HTML output - variables in JavaScript code

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
SergeiS
Jr. Propeller Head
Posts: 7
Joined: Tue May 14, 2019 9:18 am

Flare 2020 R2 - HTML output - variables in JavaScript code

Post by SergeiS »

Hi

Just wanted to share our recent experience with Flare 2020 R2.
I hope this email can help other people, who use Flare variables inside JavaScript code.

Background

In the HTML Master Page, we have JavaScript code that contains Flare variables for URLs that lead to our PDF books.

Code: Select all

<script type="text/javascript">
   function downloadPDF() {
   var pdfURL = '<MadCap:variable name="Book_Variables.File_ID" />';
   var win = window.open(pdfURL, '_blank');
   }
</script>
Note - In the Skin Topic Toolbar, we added a new button and configured the above function "downloadPDF()" as its event.

Issue

When we built an HTML output in Flare 2020 R2, we noticed that all these URLs are broken because the URLs resolved from Flare variables were wrapped in a special style.
This does NOT happen in Flare 2020 or Flare 2019 versions - resolved variables in JavaScript code are NOT wrapped in any style.

Root Cause

In Flare 2020 R2, all variables are always wrapped in a special style due to the new feature - Styled Variables:
https://help.madcapsoftware.com/flare20 ... iables.htm
This explanation was provided to use in a MadCap Support Ticket S025467.

Workaround

We had to change our JavaScript code to use a RegEx to extract the required URL from the resolved URL.
There several ways to do this.
This is what we did:

Code: Select all

<script type="text/javascript">
   function downloadPDF() {
   const RegExPattern = new RegExp('http(s){0,1}\:\/\/downloads\.checkpoint\.com\/download\.htm\\?ID=(\\w+)', 'i');
   var pdfURL_resolved = '<MadCap:variable name="Book_Variables.File_ID" />';
   var pdfURL_final = pdfURL_resolved.match(RegExPattern);
   var win = window.open(pdfURL_final[0], '_blank');
   }
</script>
NorthEast
Master Propellus Maximus
Posts: 6365
Joined: Mon Mar 05, 2007 8:33 am

Re: Flare 2020 R2 - HTML output - variables in JavaScript co

Post by NorthEast »

You don't need to use that workaround.

If you insert it as HTML, then it won't work.

Code: Select all

var pdfURL_resolved = '<MadCap:variable name="Book_Variables.File_ID" />';
But if you insert it in this format, then it will work.

Code: Select all

var pdfURL_resolved = '[%=Book_Variables.File_ID%]';
SergeiS
Jr. Propeller Head
Posts: 7
Joined: Tue May 14, 2019 9:18 am

Re: Flare 2020 R2 - HTML output - variables in JavaScript co

Post by SergeiS »

Thank you, Mr. Lee

The suggested syntax works like it did before!!! :mrgreen:
Post Reply