- You cannot directly work with java script function form C#. However you could intercept button click call and execute some of your code
- Yes, you need to publish your own COM object to the page. Then injected scripts can use this object to make callback to the BHO. Not sure how to exactly make it with C# though, no code samples exist. C++ sample function to inject COM object is below, hope it helps
.
HRESULT AddProperty(SHDocVw::IWebBrowser2* pBrowser, _bstr_t bstrName, _variant_t varValue)
{
CComQIPtr<IHTMLDocument> spDoc = pBrowser->Document;
CComPtr<IDispatch> spScript;
spDoc->get_Script(&spScript);
_variant_t varResult;
HRESULT hr = spScript.GetPropertyByName(OLESTR("window"), varResult.GetAddress());
CComQIPtr<IDispatchEx> spScriptEx = varResult;
DISPID id;
hr = spScriptEx->GetDispID(bstrName), fdexNameEnsure, &id);
if (SUCCEEDED(hr))
{
DISPID propid = DISPID_PROPERTYPUT;
DISPPARAMS dp = {NULL, NULL, 1, 1};
dp.rgdispidNamedArgs = &propid;
dp.rgvarg = &varValue;
hr = spScriptEx->InvokeEx(id, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dp, NULL, NULL, NULL);
}
return hr;
}