« Documentation Home

opera.defineMagicFunction()

This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.

For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.

Description:

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

Parameters:

Syntax:

void defineMagicFunction (<DOMString> name, <Function> implementation)

Example:

window.opera.defineMagicFunction('getLayer', function (oRealFunc, oThis, oParam1, oParam2) {
  return oParam1.getElementById(oParam2).style;
});

// This example overrides a function f. If the this object refers to the window object, it returns false.
// Otherwise it just runs the real function instead:
window.opera.defineMagicFunction('f', function (real, thisObject) {
  if (thisObject == window) {
    return false;
  } else {
    return real.apply(thisObject, Array.prototype.slice.call(arguments, 2));
  }
});