WebGadget-Issues

Just starting out? Need help? Post your questions and find answers here.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

WebGadget-Issues

Post 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
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: WebGadget-Issues

Post 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().
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: WebGadget-Issues

Post 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
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: WebGadget-Issues

Post by Fred »

You are right, it would be still be better than nothing. I will add these function, thanks !
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: WebGadget-Issues

Post by Fred »

Added.
Post Reply