I’m using a custom OLEContainer which holds a WebBrowser control (basically, I’m trying to re-create a Xojo HTMLViewer).
- In the OLEContainer instance on the window, ProgramID is set to “Shell.Explorer”
- I can load a HTML URL just fine by calling:
OLEContainer1.content.navigate "http://example.com"
- What I can’t seem to figure out is how to execute Javascript after the page is loaded.
Microsoft Documentation WebBrowser.InvokeScript Method (System.Windows.Controls) | Microsoft Docs suggests it’s a simple call to InvokeScript.
I’ve tried all sorts of variations, but it either seems to fail silently, or I get an OLEException with the “Unkown Name” exception.
dim scriptName as string = "foobar"
dim parms() as Variant
parms.append "foo"
parms.append "bar"
dim doc as OLEObject = OLEContainer1.content.Document
// None of these work:
doc.InvokeScript(scriptName, parms) // this uses Operator_Lookup to get the InvokeScript function
dim result as variant = doc.Invoke("InvokeScript", parms) // this uses the Xojo OLEObject.Invoke function directly
Possible Issues:
- The Xojo documentation here OLEObject — Xojo documentation suggests that the parameters() array is one-based rather than zero based, but I’ve tried both and neither seems to work.
- the Parms is defined as an Object in some examples, or as a String array in others e.g. WebBrowser.InvokeScript Method (String, String[]) (System.Windows.Controls) | Microsoft Docs I think this is a .NET vs Win32 API difference?
- I see examples which use WebBrowser.InvokeScript() as well as WebBrowser.Document.InvokeScript() - not clear which is right.
Anyone solved this?