I'm writing a Safari Extension that adds some functionality to a web page that I don't own. I would like for my injected JavaScript page to be able to fire some JavaScript functions the host page uses, but it doesn't work. On the Console I get the message ReferenceError: Can't find variable: function_name
.
My script is specified to be an End Script, so the whole page should be loaded. The function is also called from an onclick()
handler on the page, like so:
onclick="function_name($(this).up());"
I can get a reference to that page element, but when I call element.onclick()
I get another error: TypeError: 'undefined' is not a function (evaluating '$(this).up()')
.
Oddly, when I call the JavaScript function from an AppleScript (do JavaScript "function_name()" in page
) it works fine. How can I trigger these functions?