Well, as far as I can see your code will not do much of anything! Not sure how exactly it prevents popups from showing?
Why not use a Purebasic navigation callback?
Anyhow, the following COMatePLUS code is a quick hack and prevents the web-gadget from displaying any additional window's; pop-ups or other!
If you want more control over the pop-ups (e.g. decide which links to allow etc.) then switch my use of the 'NewWindow2' event for 'NewWindow3' and read up on this event!
Code: Select all
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
Define browser.COMateObject
;-BROWSER CALLBACK.
;/////////////////////////////////////////////////////////////////////////////////
;The following is the event procedure for our browser object.
;We use this in order to prevent new windows being opened from our web-gadget.
Procedure BrowserEventProc(Object.COMateObject, eventName$, parameterCount)
Protected *ptrBoolean.WORD
If eventName$ = "NewWindow2"
;The second parameter for this event is a boolean passed by reference which we simply set to #True to cancel the navigation.
If Object\IsEventParamPassedByRef(2, @*ptrBoolean)
;Cancel the navigation.
*ptrBoolean\w = #VARIANT_TRUE
EndIf
EndIf
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
URL$ = "http://www.mathsguru.co.uk" ;Try clicking the 'Acrobat reader' link which would normally open a new window.
#WebGadget = 0
If OpenWindow(0, 0, 0, 800, 600, "WebGadget - cancel pop-ups", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(#WebGadget, 0, 0, WindowWidth(0),WindowHeight(0), URL$)
browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA))
If browser
;Set the 'global' event handler for the browser object.
;We wish to trap the "NewWindow2" event which means that we must use the DWebBrowserEvents2 out-going interface.
;In order to over-ride COMatePLUS' selection of 'connection point' we pass a pointer to the IID of the DWebBrowserEvents2 out-going interface
;within the second optional parameter.
If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
browser\SetEventHandler(#COMate_CatchAllEvents, @BrowserEventProc(), 0, iid)
Else
MessageRequester("COMatePLUS -web demo", "IID for the DWebBrowserEvents2 interface was not found on this system!" + #CRLF$ + #CRLF$ + "Please contact the author of COMatePLUS.")
EndIf
Repeat
Event = WaitWindowEvent();
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
browser\Release()
Else
MessageRequester("COMatePLUS - cancel pop-ups demo", "Couldn't create the browser object!")
EndIf
EndIf
I may look like a mule, but I'm not a complete ass.