Fire Javascript Event on Search (HTML5)

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
ThomasH
Propeller Head
Posts: 21
Joined: Wed Apr 25, 2012 4:06 am

Fire Javascript Event on Search (HTML5)

Post by ThomasH »

Hi,
we just recently updated to Flare Version 8 and changed our Output from "normal" WebHelp to HTML5 Output.

My question is: Is there any possiple way to fire a javascript event (onClick or smth similar) when someone searches something in our WebHelp? In our old Output the Javascript was implemented into the MadCallAll.js file. But in the HTML5 output this file is generated while compiling - so it gets overwritten every time I am building my output.

Does anyone have an idea?

I am looking forward for any helpful response you can offer!
Thanks
Best regards.
FrankyT
Propeller Head
Posts: 56
Joined: Wed Apr 04, 2012 3:45 am
Location: United Kingdom

Re: Fire Javascript Event on Search (HTML5)

Post by FrankyT »

Hi Thomas,

Firstly, are you aware that you can specify custom JavaScript in HTML5 skins by entering it in the Toolbar settings? -
javascript-in-flare.png
To run a custom function on page load, you need to use this syntax:

Code: Select all

function myCustomStuff() {
    ... Stuff ...
}

window.onload=myCustomStuff;
Note that you mustn't include brackets in the window.onload statement: you're not calling the function here, you're assigning it.

Regarding your query about firing an onClick event: you could use JavaScript to add an onclick handler to the search submit button, which in turn invokes the click() method of the element that you want to receive the simulated click. E.g.

Code: Select all

function customiseSubmit() {
        // Locate the search button. NB getElementByClass isn't a standard JavaScript function - see below.
    searchButton = getElementByClass("div", "search-submit");
        // Add an onclick handler to the submit button, that runs the function which simulates the click:
    searchButton.onclick = simulateClick();
}

function simulateClick() {
        // Locate the element that you want to receive the simulated click:
    receiverElement = ### YOUR CODE HERE ###;
    receiverElement.click();
}

function getElementByClass(element, class) {
        // You'll need to implement this function yourself. PM me if you want tips.
    ... Stuff ...
}

window.onload=customiseSubmit;
There is a succinct explanation of the click() method here: http://www.randomsnippets.com/2008/03/0 ... avascript/
You do not have the required permissions to view the files attached to this post.
ThomasH
Propeller Head
Posts: 21
Joined: Wed Apr 25, 2012 4:06 am

Re: Fire Javascript Event on Search (HTML5)

Post by ThomasH »

Hi Franky,

thank you very much for you response.
I was aware that I could specify custom Javascript in the skin but we were missing the wood for the trees and couldn't think of any way to adress the button.
Your approach was exactly what we needed and with some modifications we were able to implement the script just as we wanted.

Again, thank you for your comment!
FrankyT
Propeller Head
Posts: 56
Joined: Wed Apr 04, 2012 3:45 am
Location: United Kingdom

Re: Fire Javascript Event on Search (HTML5)

Post by FrankyT »

No problem, and glad you could make sense of my answer! I'd needed to do something very similar myself, so fortunately it was fresh in my mind.
Post Reply