krl

Calling my own JavaScript functions


This problem only manifests itself when my app runs through the KBX. Running it in a bookmarklet works fine. I used to be able to do this, but it doesn't work any more.

Here's what I have. There's an onclick attribute on a <p> tag that calls a JavaScript function:

<p conclick="window.a163x134_log(this); return false;"></p>

Here's what my function looks like:

emit <|
    window.a163x134_log = function(obj) {
        // Do something
    };
|>;

I've tried using a regular function name (not attached to window) and namespacing it with KOBJ. Neither of those works. The error message I get reads "Uncaught TypeError: Object [object DOMWindow] has no method 'a163x134_log'".

Is this a bug or do I need to change something in my code?


Solution

  • Sounds like you are running into a sandbox issue. Javascript running in the UBX runs in the sandbox separate from the page.

    I have a blog post that may or may not be out of date http://geek.michaelgrace.org/2011/03/kynetxs-new-sandboxed-browser-extensions/

    You should also try using the 'use resource' to pull in a javascript file. I believe that gets pulled into the page and not the sandbox.

    Also see Kynetx app not working when installed via KBX extension on Chrome