Webgadget and capturing events

Just starting out? Need help? Post your questions and find answers here.
scriptmaster
User
User
Posts: 15
Joined: Fri Mar 13, 2009 3:13 pm
Location: Chennai, India

Webgadget and capturing events

Post 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?
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post 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
Post Reply