Webgadget Open in a new tab and new window

Just starting out? Need help? Post your questions and find answers here.
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Webgadget Open in a new tab and new window

Post 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.
User avatar
Tombmyst
User
User
Posts: 11
Joined: Thu Jul 04, 2013 2:34 am
Location: Québec

Re: Webgadget Open in a new tab and new window

Post by Tombmyst »

Take some time to think about it and I'm pretty sure you'll find a way!
Tombmyst
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Re: Webgadget Open in a new tab and new window

Post by a_carignan »

Tombmyst wrote:Take some time to think about it and I'm pretty sure you'll find a way!
:shock:
I do not have time to waste looking for solutions that already exists! :(
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: Webgadget Open in a new tab and new window

Post 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
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Re: Webgadget Open in a new tab and new window

Post 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. :D
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Webgadget Open in a new tab and new window

Post 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. :)
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: Webgadget Open in a new tab and new window

Post 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. :D
You're welcome. This is where I got the information for the "NewWindow3" event.
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Re: Webgadget Open in a new tab and new window

Post by a_carignan »

Thanks for your help. :D
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Re: Webgadget Open in a new tab and new window

Post 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. :idea:
I would like to know if there are ways to know the object that was clicked to customize my popup-menu? :?:
Post Reply