execute javascript in embedded web browser

14 views
Skip to first unread message

dvir.v...@gmail.com

unread,
Oct 11, 2018, 2:21:22 AM10/11/18
to ComfyJ Forum
hi,

I generate the web browser classes (internet control).
one of the IWebBrowser2 class has getDocument() method.

I was wondering, how can I execute javacript method from getDocument() method.
do I have to generate the mshtml.dll ?

please help !!!

Olga Zarubina

unread,
Oct 11, 2018, 5:53:52 AM10/11/18
to dvir.v...@gmail.com, comfyj...@teamdev.com
Hi Dvir,

Thank you for your question!

Here is a sample implementation of such functionality:

public String executeScript(final String function, final String param) { try { final Object[] rv = {null}; getOleMessageLoop().doInvokeAndWait(new Runnable() { public void run() { IDispatch documentDispatch = iWebBrowser2.getDocument(); IHTMLDocument document = new IHTMLDocumentImpl(documentDispatch); IDispatch script = document.getScript(); rv[0] = ((Variant) Automation.invokeDispatch(script, function, new Parameter[]{new Variant(param)}, Variant.class)).getValue(); System.out.println("rv = " + rv[0]); //Release COM interfaces as soon as we don't need them anymore script.setAutoDelete(false); script.release(); document.setAutoDelete(false); document.release(); documentDispatch.setAutoDelete(false); documentDispatch.release(); } }); if ((rv != null) && (!rv.toString().equalsIgnoreCase("null"))) { return rv.toString(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }

Please let us know if you have any further questions on this particular case.

Best regards,
Olga
 Zarubina

Customer Service Manager | TeamDev, Ltd.
Phone:
 +380 57 766-4300
olga.zarubina@teamdev.com | www.teamdev.com

--
You received this message because you are subscribed to the Google Groups "ComfyJ Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to comfyj-forum...@teamdev.com.
To view this discussion on the web visit https://groups.google.com/a/teamdev.com/d/msgid/comfyj-forum/90eba65e-c4f0-45b6-b482-6992486fdcee%40teamdev.com.
Reply all
Reply to author
Forward
0 new messages