WebGadget links open in default browser?

Everything else that doesn't fall into one of the other PB categories.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

WebGadget links open in default browser?

Post by Dude »

If I have a WebGadget in my app, can I make any clicked links open OUTSIDE of my app and in the PC's normal default browser instead? Sort of like the "target=_blank" meta-tag but for links that don't have that tag? I basically want to use the WebGadget to show an index page of links (that I didn't create, and hosted by someone else) but they open outside of my app. Thanks!
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: WebGadget links open in default browser?

Post by RSBasic »

You can add a WebGadget callback and check the links.
Look in the help for WebGadget and #PB_Web_NavigationCallback.
Image
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: WebGadget links open in default browser?

Post by Dude »

Wow, I can't believe it was that simple! :shock: Thanks!

For my future reference:

Code: Select all

Procedure NavigationCallback(Gadget, Url$) 
  If Url$= "http://www.purebasic.com/news.php" 
    RunProgram(Url$) ; Open in default browser.
    ProcedureReturn #False 
  Else 
    ProcedureReturn #True 
  EndIf 
EndProcedure 

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
Post Reply