WebGadget: Links with target="_blank" do not work?

Linux specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

WebGadget: Links with target="_blank" do not work?

Post by Kukulkan »

Hello,

I tried this [PB 5.24 LTS, Kubuntu 14.04]:

Code: Select all

html.s = "<!doctype html><html lang=\qen\q><head><meta http-equiv=\qcontent-type\q content=\qtext/html; charset=UTF-8\q></head>"+
         "<body>" + 
         "<a href=\qhttp://www.purebasic.com\q target=\q_self\q>Open here</a><br>" +
         "<a href=\qhttp://www.purebasic.com\q target=\q_blank\q>Open new window</a>" + 
         "</body>" +
         "</html>"

html.s = ReplaceString(html.s, "\q", Chr(34))

path.s = GetTemporaryDirectory() + "test.html"

CreateFile(0, path.s)
WriteString(0, html.s)
CloseFile(0)

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "file://" + path.s)
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
On Windows, both links are working. On Linux, the second one does not. How to enable this?

Thanks,

Kukulkan
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: WebGadget: Links with target="_blank" do not work?

Post by Shardik »

Kukulkan wrote:Links with target="_blank" do not work?
They work but you have to connect the signal "new-window-policy-decision-requested" to a callback:

Code: Select all

EnableExplicit

#HTML = "<!doctype html>" +
  "<html lang='en'>" +
  "  <head>" +
  "    <meta http-equiv='content-type' content='text/html; charset=UTF-8'>" +
  "  </head>" +
  "  <body>" +
  "    <a href='http://www.purebasic.com' target='_self'>Open here</a><br>" +
  "    <a href='http://www.purebasic.com' target='_blank'>Open new window</a>" +
  "  </body>" +
  "</html>"

ImportC "-lgobject-2.0"
  g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData,
    *ClosureNotify, ConnectFlags.I)
EndImport

ImportC "-lwebkitgtk-1.0"
  webkit_web_navigation_action_get_original_uri(*NavigationAction)
  webkit_web_view_load_string(*WebView, Content.P-UTF8, *MIMEType, *Encoding,
    *BaseURI)
EndImport

ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction,
  *PolicyDecision, UserData)
  Protected URL.S = PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction),
    -1, #PB_UTF8)
  ; ----- Open URL in new window of default browser
  RunProgram("xdg-open", URL, GetCurrentDirectory())
EndProcedure

OpenWindow(0, 100, 100, 640, 480, "WebGadget demo")
WebGadget(0, 5, 5, 630, 470, "")
webkit_web_view_load_string(GadgetID(0), #HTML, 0, 0, 0)
g_signal_connect_data(GadgetID(0), "new-window-policy-decision-requested",
  @WebGadgetCallback(), 0, 0, 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: WebGadget: Links with target="_blank" do not work?

Post by Kukulkan »

Thank you Shardik

I think that Fred should have done this by default. This is, in fact, a replacement for the existing PB functions.

Thanks anyway,

Kukulkan
Post Reply