I have a WebBrowser control set up with ObjectForScripting such that I can call C# methods from JavaScript hosted in the browser control.
Everything seems to be going fine except that in my unit tests I have some checks on the window.external methods I am using and it turns out that...
window.external.MyMethod
...seems to work just the same as...
window.external.MyMethod()
What if I need a reference to the method? Or in the case of my unit test:
typeof(window.external.MyMethod) === 'function'
But this calls the method (and fails because it returns the type of whatever was returned by the method)
How do I g开发者_Python百科et a reference to the method without calling it?
Looking at what documentation I could find, it looks like referring to any member of window.external
initiates a call to the host:
...a reference to "window.external.speech" will call the host to resolve the name "speech."
I'm not specifically familiar with this API, but it seems like you might be able instead to do something like:
window.external.checkType('MyMethod') === 'function'
Where checkType
is a function you declare within your C# code that can tell you the type of the property provided.
精彩评论