What is the equivalent for WebBrowser.ObjectForScripting in IE?

Add-in Express™ Support Service
That's what is more important than anything else

What is the equivalent for WebBrowser.ObjectForScripting in IE?
 
Omri Suissa


Guest


Hi,
When i want to "add" methods to the window.external so JS code can call my application in .net i'm using ObjectForScripting in the WebBrowser control.
What i should use in the IE.WebBrowser to do the same?

Thanks,
Omri
Posted 17 Oct, 2011 02:39:57 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Omri,

There is not any equivalent in IE.WebBrowser. But you can use a reference to the iemodule.
Here is an example: http://www.add-in-express.com/files/projects_pub/access_bho_from_js.zip
Posted 17 Oct, 2011 09:53:29 Top
Omri Suissa


Guest


Hi,
I didn't understand your response.
If i was doing it on C++ i was using the SetUIHandler and intercept the GetExternal message.

for example:
http://msdn.microsoft.com/en-us/library/aa753260(v=vs.85).aspx

and:
http://msdn.microsoft.com/en-us/library/aa753256(v=vs.85).aspx

... ::GetExternal(IDispatch **ppDispatch)
{
// Assumes you inherit from IDispatch
*ppDispatch = (IDispatch*)this;
(*ppDispatch)->AddRef();

return S_OK;
}

What i'm looking is a way to do the same in your framework

P.S
I can use a third party project from here:
http://www.codeproject.com/KB/cs/advhost.aspx
do to so but i assume that your framework already taking care of that...

Thanks,
Omri
Posted 17 Oct, 2011 11:20:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Omri, the IE object model doesn't provide a reference to the WebBrowser control. If you install your own UI handler, it may affect other extensions. Please look at the example above.
Posted 17 Oct, 2011 11:45:38 Top
Omri Suissa


Guest


Hi,
So what you are offering is to set the BHO object as a member in the JS global namespace instead of using the window.external.
1) what about iframes? that means that i need to "run" it on every iframe (window) in the documents right?
2) i know that there are problems in IE 8 and 9 when interfering with the JS in iframes code on download complete event. do you know anything about it?

Omri
Posted 18 Oct, 2011 03:33:43 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Omri.

1. Right. At least, I don't know another way.
2. I am not aware of such a problem.
Posted 18 Oct, 2011 07:53:25 Top
Omri Suissa


Guest


Its very rare and it took us almost year and a half to find it but there are some websites that when you run js code in download complete event you are massing the site's js execution. therefore i prefer not to run js code in download complete.
Posted 18 Oct, 2011 08:09:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Omri, the access_bho_from_js example shows of how you can initialize a js field if it is available in the js code. And it doesn't run any js code in the DownloadComplete event handler.
Posted 18 Oct, 2011 10:43:44 Top
Omri Suissa


Guest


Maybe i'm wrong but i assumed that:
scriptEngine.GetType().InvokeMember("bhoModule", BindingFlags.SetProperty, null, scriptEngine, new object[] { this } );


is doing "window.bhoModule = &spDisp".

Omri
Posted 18 Oct, 2011 11:03:30 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
The 'bhoModule' is defined in js as follows:

<html>
<head>
<script type="text/javascript">

var bhoModule = null;

</script>
</head>

....

</body>
</html>

Does this code produce any problems?
Posted 18 Oct, 2011 11:41:51 Top