Page 1 of 1
Webgadget and capturing events
Posted: Fri Mar 13, 2009 4:18 pm
by scriptmaster
Is WebGadget cross platform?
Suppose I have a <input type="button" value="Click me" /> button. Is it possible to capture an onclick event of the button in PB?
Posted: Fri Mar 13, 2009 7:57 pm
by utopiomania
Yes I think so?
Here's one way to capture the buttonclick event:
Code: Select all
enumeration
#WIN
#WEB
endEnumeration
global winW = 660, winH = 480
declare openMainWindow()
declare navigationCallback(id, url.s)
declare.s userInterfacePage1()
;-program entry
openMainWindow()
;-program event handler
repeat
event = waitWindowEvent()
select event
case #PB_EVENT_SIZEWINDOW
winW = windowWidth(#WIN)
winH = windowHeight(#WIN)
resizeGadget(#WEB, 0, 0, winW, winH)
case #PB_EVENT_CLOSEWINDOW
;-program exit
;-
end
endSelect
forever
procedure openMainWindow()
if openWindow(#WIN, 0, 0, winW, winH, "", $CF0001)
webGadget(#WEB, 0, 0, winW, winH, "")
;load the html
setGadgetItemText(#WEB, #PB_WEB_HTMLCODE, userInterfacePage1())
;callback to monitor navigation
setGadgetAttribute(#WEB, #PB_WEB_NAVIGATIONCALLBACK, @navigationCallback())
endIf
endProcedure
procedure navigationCallback(id, url.s)
url = lcase(url)
if findString(url, "btn1_onclick", 1)
;handle event...
messageRequester("Event", "Button Clicked")
procedureReturn 0
endIf
;block drag-drop
procedureReturn 0
endProcedure
procedure.s userInterfacePage1()
html.s + "<input type='button' value='Click me' onclick='window.location=" + #DQUOTE$ +"btn1_OnClick" + #DQUOTE$ + "'/>" + #CR$
procedureReturn html
endProcedure