views:

61

answers:

3

Say a webpage has a function like:

function abc (){
return 'abc';
}

How would I execute and receive the return value of that function from my extension? I've tried this, no dice:

var s = getBrowser.contentWindow.abc();

Thanks in advance!

A: 

Look at this http://stackoverflow.com/questions/151555/how-do-i-execute-a-page-defined-javascript-function-from-a-firefox-extension

Gaby
The answer to that question (the one that was at Google Groups) doesn't work for me. ( said above... )
motionman95
@motionman95, have you looked at https://developer.mozilla.org/en/Components.utils.evalInSandbox ?
Gaby
Yes, it didn't work either.EDIT:It always says the function doesn't exist.
motionman95
A: 

I think I've solved my own problem with:

getBrowser().contentWindow.wrappedJSObject.funcFromPage();
motionman95
or `content.wrappedJSObject.funcFromPage()`
matyr
A: 

I think that if you want to do this without major security holes, you need to be using XPCSafeJSObjectWrapper, but I'm having trouble finding good documentation on it. https://developer.mozilla.org/en/XPConnect_wrappers has a little bit. (It might be that it happens automatically when doing the above, but I'm not sure.)

David Baron