Page 1 of 1

WebGadget-Issues

Posted: Thu Apr 17, 2014 2:15 pm
by Peter
Hello,

it seems, that the WebGadget doesn't fire any event. And GetGadgetItemText() doesn't return values.

Code: Select all

Enumeration
  #Window
  #ButtonGadget
  #WebGadget
EndEnumeration

Procedure WebGadgetEvents()
  
  ; not fired?
  
  Debug "!!! WebGadgetEvent"
  Debug "EventGadget(): " + EventGadget()
  Debug "EventType(): "   + EventType()
  Debug "----"
  
EndProcedure

Procedure ButtonGadgetEvents()
  
  ; - GetGadgetItemText(): The following constants can be used to get information

  Debug "#PB_Web_HtmlCode: "      + GetGadgetItemText(#WebGadget, #PB_Web_HtmlCode)      ; Get the html code from the gadget.
  Debug "#PB_Web_PageTitle: "     + GetGadgetItemText(#WebGadget, #PB_Web_PageTitle)     ; Get the current title For the displayed page.
  Debug "#PB_Web_StatusMessage: " + GetGadgetItemText(#WebGadget, #PB_Web_StatusMessage) ; Get the current statusbar message.
  Debug "#PB_Web_SelectedText: "  + GetGadgetItemText(#WebGadget, #PB_Web_SelectedText)  ; Get the currently selected text inside the gadget.

EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ButtonGadget(#ButtonGadget, 10, 10, 300, 30, "GetGadgetItemText(#WebGadget, ...)")
BindGadgetEvent(#ButtonGadget, @ButtonGadgetEvents())

WebGadget(#WebGadget, 10, 50, WindowWidth(#Window) - 20, WindowHeight(#Window) - 60, "http://www.purebasic.com")
BindGadgetEvent(#WebGadget, @WebGadgetEvents())
Thanks in advance & Greetings ... Peter

Re: WebGadget-Issues

Posted: Sat Apr 26, 2014 11:40 am
by Fred
Unfortunately, it doesn't seems to get the html code and other iframe info unless it's on the same domain than your app. It pretty much reduces the use of such functions, so for now it won't be available. No events are supported by the WebGadget().

Re: WebGadget-Issues

Posted: Sun Apr 27, 2014 9:30 am
by Peter
Fred wrote:Unfortunately, it doesn't seems to get the html code and other iframe info unless it's on the same domain than your app.
ok, but what about local webpages (within the same domain)?
Fred wrote:No events are supported by the WebGadget().
it would be nice if at least the loaded event is supported. Here is my attempt:

Code: Select all

Enumeration
  #Window
  #ButtonGadget
  #WebGadget
EndEnumeration

Procedure GadgetElement(Gadget, UseJquery.b = #True)
  Protected gadgetObject = GadgetID(Gadget) 
  ! if (v_gadgetObject && v_gadgetObject.div) { return v_UseJquery ? $(v_gadgetObject.div) : v_gadgetObject.div; }
EndProcedure
  
Procedure.s GetWebGadgetItemText(WebGadget, Attribute)

  ; note that GetWebGadgetItemText() doesn't work
  ; with pages outside your domain because of security
  ; reasons

  Protected ReturnValue.s = ""
  
  Protected WG = GadgetElement(WebGadget)
  
  Select Attribute
      
    Case #PB_Web_HtmlCode      ; Get the html code from the gadget.
      
      ! try { v_ReturnValue = v_WG.find("iframe").contents().find("html").html() }
      ! catch(exception) { v_ReturnValue = exception }
      ! finally { }  
      
    Case #PB_Web_PageTitle     ; Get the current title For the displayed page.
      
      ! try { v_ReturnValue = v_WG.find("iframe").contents().find("title").html() }
      ! catch(exception) { v_ReturnValue = exception }
      ! finally { }  
      
    Case #PB_Web_StatusMessage ; Get the current statusbar message.
      
      ReturnValue = "???"
      
    Case #PB_Web_SelectedText  ; Get the currently selected text inside the gadget.
      
      ! try {
      !   var iframe = v_WG.find("iframe")[0];
      !   var idoc = iframe.contentDocument || iframe.contentWindow.document; // For IE.
      !   v_ReturnValue = idoc.getSelection();
      ! }
      !   catch(exception) { v_ReturnValue = exception }
      !   finally { }  
            
    EndSelect
  
  ProcedureReturn ReturnValue  
  
EndProcedure

Procedure ButtonGadgetEvents()
  
  ; - GetWebGadgetItemText(): The following constants can be used to get information
  
  Debug "#PB_Web_HtmlCode: "      + GetWebGadgetItemText(#WebGadget, #PB_Web_HtmlCode)      ; Get the html code from the gadget.
  Debug "#PB_Web_PageTitle: "     + GetWebGadgetItemText(#WebGadget, #PB_Web_PageTitle)     ; Get the current title For the displayed page.
  Debug "#PB_Web_StatusMessage: " + GetWebGadgetItemText(#WebGadget, #PB_Web_StatusMessage) ; Get the current statusbar message.
  Debug "#PB_Web_SelectedText: "  + GetWebGadgetItemText(#WebGadget, #PB_Web_SelectedText)  ; Get the currently selected text inside the gadget.
  
EndProcedure
  
Procedure WebGadgetLoaded()
  DisableGadget(#ButtonGadget, #False)
EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
ButtonGadget(#ButtonGadget, 10, 10, 300, 30, "GetGadgetItemText(#WebGadget, ...)")
BindGadgetEvent(#ButtonGadget, @ButtonGadgetEvents())
DisableGadget(#ButtonGadget, #True)
  
; WebGadget(#WebGadget, 10, 50, WindowWidth(#Window) - 20, WindowHeight(#Window) - 60, "http://www.purebasic.com")
WebGadget(#WebGadget, 10, 50, WindowWidth(#Window) - 20, WindowHeight(#Window) - 60, "test.html")
   
WB = GadgetElement(#WebGadget)
WebGadgetLoaded = @WebGadgetLoaded()
! v_WB.find("iframe").load( v_WebGadgetLoaded ); // calling WebGadgetLoaded(), when page is loaded
Thanks & Greetings ... Peter

Re: WebGadget-Issues

Posted: Mon Apr 28, 2014 1:38 pm
by Fred
You are right, it would be still be better than nothing. I will add these function, thanks !

Re: WebGadget-Issues

Posted: Mon Apr 28, 2014 2:46 pm
by Fred
Added.