Insert Javascript in main frame file

This forum is for all Flare related Tips and Tricks.
Have a tip or trick you use while working in Flare? Share it here.
Post Reply
Ineffable
Sr. Propeller Head
Posts: 152
Joined: Mon Jan 15, 2007 3:08 pm
Location: Bay Area, CA

Insert Javascript in main frame file

Post by Ineffable »

To access my help system, a user needs to login. The developers have given me Javascript that authenticates the session and verifies that a cookie is present to let the user access the system; if the cookie is not, the user is kicked out.

I tried putting this supplied Javascript using the function provided in the 'Custom Javascript to include in Toolbar page' function in the WebHelp Toolbar section of the Skin. However, that creates problems since it is only authenticating that iframe, not the entire frameset.

I had them evaluate my generated WebHelp system, and they asked me if I could insert the Javascript in the main frame file (usually index.htm). I said I could, but only after my WebHelp system is generated. Which begs this question: Can I have the script insert BEFORE compiling?

I think I found the file I need to edit in C:\Program Files\MadCap Software\MadCap Flare V3\Flare.app\Resources\WebHelp\Default.htm. However, I inserted my script in there and I got a compiler error when trying to generate my WebHelp system. I placed the script before and after the <head>, to no avail.

Any ideas?
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: Insert Javascript in main frame file

Post by LTinker68 »

If by "after the <head>" you mean you put it between the <head> and </head> tags, then theoretically it should have worked (so long as it was also inside of <script> tags).

However, I don't think you want to do that, since the frame page (and therefore the validation code) is always in the browser. I think a better method might be to change the output file name from Default.htm to ourHelp.htm (or whatever). Then create an HTML file and call it default.htm or index.htm or whatever your web server defaults to. Inside that page, have the code to validate the login, and if they're validated, then it automatically loads the ourHelp.htm page. The web server can also be set up to redirect the user to the default.htm/index.htm page if the user tries to go directly to ourHelp.htm without logging in.

The benefits of this method is that your validation is handled by the server and a single page, which you're not responsible for -- after all, you're a technical writer, not a security or IT specialist. Unless, of course, you are. :wink: You can just go about your business of writing help without worrying about whether or not the security is in place and working properly.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Insert Javascript in main frame file

Post by NorthEast »

If I were you, I'd go back and ask your developers to sit down with you and look at the help, then tell you where and how their script should fit in with it.
Ineffable
Sr. Propeller Head
Posts: 152
Joined: Mon Jan 15, 2007 3:08 pm
Location: Bay Area, CA

Re: Insert Javascript in main frame file

Post by Ineffable »

Dave Lee wrote:If I were you, I'd go back and ask your developers to sit down with you and look at the help, then tell you where and how their script should fit in with it.
I ended up placing the script on the master page. That way every page of my output is "protected."

Inserting it in the master frame file would have allowed anyone to by pass the login by deep linking to the main frame topic page. Authentication would have occurred probably only when they clicked the "Open this topic with navigation" link.

What's still strange is that the script would cause a compilation error when it was inserted manually using the internal editor, but was fine when insert using the Insert > Script command on the master page. I placed it between the Breadcrumbs and Body proxy. It also didn't like me inserting the script in the main Default.htm file Flare uses as a template to create the main frame file.
Ryan Cerniglia

Re: Insert Javascript in main frame file

Post by Ryan Cerniglia »

This is due to the strict XML compliance that Flare requires. In the future, you should be able to use CDATA tags like so to insert javascript into the head:

Code: Select all

<![CDATA[ 

JavaScript goes here!

]]>
Ineffable
Sr. Propeller Head
Posts: 152
Joined: Mon Jan 15, 2007 3:08 pm
Location: Bay Area, CA

Re: Insert Javascript in main frame file

Post by Ineffable »

I just found out that for some server-side authentication to work, I have to place some Javascript in the main frameset file (the OUTPUT FILE field in the BASIC tab of the Target).

I can place it in there manually after I generate an output; is there a way to place it in the source files?
Ineffable
Sr. Propeller Head
Posts: 152
Joined: Mon Jan 15, 2007 3:08 pm
Location: Bay Area, CA

Re: Insert Javascript in main frame file

Post by Ineffable »

bump
Pernice
Propeller Head
Posts: 21
Joined: Thu Dec 01, 2011 5:39 am

Re: Insert Javascript in main frame file

Post by Pernice »

Ryan Cerniglia wrote:This is due to the strict XML compliance that Flare requires. In the future, you should be able to use CDATA tags like so to insert javascript into the head:

Code: Select all

<![CDATA[ 

JavaScript goes here!

]]>
Following the above suggestion, I tried adding the following script to the head section of the Default.htm file in the folder:
C:\Program Files\MadCap Software\MadCap Flare V8\Flare.app\Resources\WebHelpMobile\Basic

<script type="text/javascript">//<![CDATA[
window.location="/help/jsversion/";
//]]></script>

but when I attempted to build the help, Flare aborted as it tried to create the Default.htm file, with a message saying "Object reference not set to an instance of an object." Is this because Flare is looking for /help/jsversion/ (which doesn't exist as far as Flare is concerned) or is it breaking for another reason?
rob hollinger
Propellus Maximus
Posts: 661
Joined: Mon Mar 17, 2008 8:40 am

Re: Insert Javascript in main frame file

Post by rob hollinger »

The code should look like this:

Code: Select all

<script type="text/javascript">
/* <![CDATA[ */
 window.location="/help/jsversion/";
/* ]]> */
</script>
This will work in all the start pages but the Basic page. The basic for mobile output is supposed to be script free and that is probably what is throwing the error in the compiler. It will have to be added after the project is compiled.
Rob Hollinger
MadCap Software
Post Reply