A while ago Freak posted some code which allows one to execute JavaScript commands against a WebGadget etc. Ricardo juggled it around a bit and I have just translated a small part of it to COMate.
I reckon it could be useful for those who work with this kind of stuff.
Code: Select all
IncludePath "..\"
XIncludeFile "COMate.pbi"
Define.COMateObject WebObject
Procedure.i ExecuteJavaScript(Gadget, command$)
Protected browser.COMateObject, documentDispatch.COMateObject, script.COMateObject
Protected result
browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(gadget), #GWL_USERDATA))
If browser
documentDispatch = browser\GetObjectProperty("Document")
If documentDispatch
script = documentDispatch\GetObjectProperty("script")
If script
result = script\Invoke("eval('" + command$ + "')")
script\release()
EndIf
documentDispatch\Release()
EndIf
browser\Release()
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 10000, 0, 0, 0, "WebGadget", #PB_Window_SystemMenu|#PB_Window_Maximize)
WebGadget(0, 0, 0, WindowWidth(0)+50,WindowHeight(0)-100, "http://www.purebasic.fr/english/posting.php?mode=reply&t=33983")
ButtonGadget(1,50,WindowHeight(0)-50,150,25,"Fill & Send")
Repeat
Event = WaitWindowEvent();
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
xMessage$ = "Hello from PB :)"
ExecuteJavaScript(0,"document.all.message.value=" + Chr(34) + xMessage$ + Chr(34))
ExecuteJavaScript(0,"document.all.preview.click()")
;DO NOT run the following line as it will automatically post in the COMate thread in the PB forums!
; ExecuteJavaScript(0,"document.post.post.click()")
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
Until GetAsyncKeyState_(#VK_ESCAPE)
EndIf