Action for a button is the Javascript code that will run when the Button will be activated.
This code has some specific features:
That is a main cause of errors: As the Button is on a DFrame the developers often confuse the code in the page inserted in the DFrame and the code of Buttons.
§ Quotes must be protected (\') or replaced by double quotes(")
§ if the code calls a function with a parameter:
o If the parameter is a string: action = 'myFunction("' + myVariable + "')'
o If the parameter is not a string: action = 'myFunction(' + myVariable + ")'
Example:
var dFrame = new DFrame(parameters)
//Add a Button
dFrame.addButton('set green BgColor', 'dFrame.setBackgroundColor("green")')
or
dFrame.addButton('set green BgColor', 'thisDFrame.setBackgroundColor("green")')
The 'thisDFrame' keyword is also authorized as parameter for a function
or method:
dFrame.addButton('Tell url', 'alert(thisDFrame.getURL())')
Demo
file: addBar.html
Run the example
See the source code
Example:
button = dFrame.addButton('Use context Menu 2',
'this.flipFlop()')
button.flipFlop = function() { … }
Demo
file: addMenu-1.html