opera.defineMagicVariable()

Description:

This method can be used by to override global variables defined by regular scripts in a page.

Parameters:

  • name: String giving the name of the variable to be overridden.
  • getter: Function to be run whenever a script attempts to access the contents of the variable. Any value returned by the function is used as the value of the variable. The function receives the current value of the variable as parameter.
  • setter: Optional function to be run whenever a script attempts to set the value of the variable. The value that the script was attempting to assign to the variable is passed to the function as parameter. If no setter function is required, the value null must be used instead.

Syntax:

void defineMagicVariable (<DOMString> name, <Function> getter, <Function> setter)

Example:

window.opera.defineMagicVariable('isGoodBrowser', function (curVal) {
  return true;
}, function (newVal) {
  if (!newVal) {
    window.status = 'Repairing script';
  }
});

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

You must be logged in to write a comment. If you're not a registered member, please sign up.