Page 1 of 1
Webgadget Open in a new tab and new window
Posted: Wed Sep 04, 2019 10:09 am
by a_carignan
Hello, I would like to know how to manage the opening of a page in a new tab and new window from the popupmenu create pat the webgadget?
Thank you in advance.
Re: Webgadget Open in a new tab and new window
Posted: Thu Sep 05, 2019 11:14 am
by Tombmyst
Take some time to think about it and I'm pretty sure you'll find a way!
Re: Webgadget Open in a new tab and new window
Posted: Fri Sep 06, 2019 9:00 am
by a_carignan
Tombmyst wrote:Take some time to think about it and I'm pretty sure you'll find a way!
I do not have time to waste looking for solutions that already exists!

Re: Webgadget Open in a new tab and new window
Posted: Fri Sep 06, 2019 5:25 pm
by wombats
You need COMatePlus for this, which you can download from
https://www.rsbasic.de/backups/. This only handles "Open in new window". Someone more knowledgeable than me might know how to edit the context menu to enable "Open in new tab" and intercept it.
Windows only.
Code: Select all
EnableExplicit
XIncludeFile "COMatePLUS.pbi"
Declare WebEventProc(obj.COMateObject, evtName.s, paramCount)
Structure BrowserWindow
id.i
web.i
com.COMateObject
EndStructure
Global Quit.b, NewList BrowserWindows.BrowserWindow()
Procedure OnWindowSized()
Protected *dat
*dat = GetWindowData(EventWindow())
ChangeCurrentElement(BrowserWindows(), *dat)
ResizeGadget(BrowserWindows()\web, #PB_Ignore, #PB_Ignore, WindowWidth(BrowserWindows()\id) - 20, WindowHeight(BrowserWindows()\id) - 20)
EndProcedure
Procedure OnWindowClosed()
Protected *dat
*dat = GetWindowData(EventWindow())
ChangeCurrentElement(BrowserWindows(), *dat)
BrowserWindows()\com\Release()
CloseWindow(BrowserWindows()\id)
DeleteElement(BrowserWindows())
If ListSize(BrowserWindows()) = 0
Quit = #True
EndIf
EndProcedure
Procedure OpenBrowserWindow(url.s)
Protected iid.IID
AddElement(BrowserWindows())
BrowserWindows()\id = OpenWindow(#PB_Any, 0, 0, 640, 480, url, #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
BrowserWindows()\web = WebGadget(#PB_Any, 10, 10, 620, 460, url)
BrowserWindows()\com = COMate_WrapCOMObject(GetWindowLongPtr_(GadgetID(BrowserWindows()\web), #GWL_USERDATA))
If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
BrowserWindows()\com\SetEventHandler(#COMate_CatchAllEvents, @WebEventProc(), 0, iid)
EndIf
SetWindowData(BrowserWindows()\id, @BrowserWindows())
BindEvent(#PB_Event_SizeWindow, @OnWindowSized(), BrowserWindows()\id)
BindEvent(#PB_Event_CloseWindow, @OnWindowClosed(), BrowserWindows()\id)
EndProcedure
OpenBrowserWindow("https://www.purebasic.com")
Repeat : WaitWindowEvent() : Until Quit = #True
Procedure WebEventProc(obj.COMateObject, evtName.s, paramCount)
Protected *ptrBool.WORD
Select evtName
Case "NewWindow3"
OpenBrowserWindow(obj\GetStringEventParam(5))
If obj\IsEventParamPassedByRef(2, @*ptrBool)
*ptrBool\w = #VARIANT_TRUE
EndIf
EndSelect
EndProcedure
Re: Webgadget Open in a new tab and new window
Posted: Sun Sep 08, 2019 9:46 am
by a_carignan
Wow, This is exactly the example that was clawing me to manage the opening of a web page in a new window. Thank you so much.
I would like to know where to find information on the commands to use to manage a web browser with ComatePlus. With luck I would find a way to manage the web page in a new tab, otherwise I would do it differently.
Once again thank you very much to you Wombats.

Re: Webgadget Open in a new tab and new window
Posted: Sun Sep 08, 2019 10:00 am
by firace
Hi a_carignan,
I had to solve similar issues when creating my PB browser (
viewtopic.php?f=14&t=72166). I can't share the entire source, but if you have specific questions that I have already resolved, I'll be happy to help or point you to relevant MSDN documentation.

Re: Webgadget Open in a new tab and new window
Posted: Sun Sep 08, 2019 6:05 pm
by wombats
a_carignan wrote:Wow, This is exactly the example that was clawing me to manage the opening of a web page in a new window. Thank you so much.
I would like to know where to find information on the commands to use to manage a web browser with ComatePlus. With luck I would find a way to manage the web page in a new tab, otherwise I would do it differently.
Once again thank you very much to you Wombats.

You're welcome.
This is where I got the information for the "NewWindow3" event.
Re: Webgadget Open in a new tab and new window
Posted: Fri Sep 13, 2019 5:22 am
by a_carignan
Thanks for your help.

Re: Webgadget Open in a new tab and new window
Posted: Tue Sep 17, 2019 5:55 am
by a_carignan
I have not found ways to make the menu accessible to open the link in a new tab.
I'm wondering if I could not use the #PB_Web_BlockPopupMenu attribute, in order to create my own popup-menu.
I would like to know if there are ways to know the object that was clicked to customize my popup-menu?
