Programming actions for buttons

Action for a button is the Javascript code that will run when the Button will be activated.

This code has some specific features:

The code will run in mainPage

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.

The code will be run thru the eval method of Javascript.

§         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 + ")'

The DFrame containing the Button can be accessed with the 'thisDFrame' keyword.

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

The Button can be accessed with the 'this' keyword.

Example:

button = dFrame.addButton('Use context Menu 2', 'this.flipFlop()')                   

button.flipFlop = function() { … }

Demo

file: addMenu-1.html

Run the example
See the source code