Board index » cppbuilder » CppWebBrowser OnNewWindow2 event handling

CppWebBrowser OnNewWindow2 event handling


2007-01-08 06:01:56 AM
cppbuilder6
I have the following code to handle "pop-ups" and valid new window launches
inside CppWebBrowser's OnNewWindow2 event :-
//---------------------------------------------------------------------------
void __fastcall TForm1::CppWebBrowser1NewWindow2(TObject *Sender,LPDISPATCH
*ppDisp,TOLEBOOL *Cancel)
{
*Cancel=true;
if (CppWebBrowser1->ReadyState<3) { ppDisp=NULL; return;}
// Some code to launch the URL in a new window...
}
//---------------------------------------------------------------------------
The problem I am having is deriving the URL that will be launched, if I do
allow the pop-up. How do I derive this from the arguments handed to the
event handler?
--
Mark Jacobs
www.jacobsm.com
 
 

Re:CppWebBrowser OnNewWindow2 event handling

Mark Jacobs wrote:
Quote
The problem I am having is deriving the URL that will be launched, if I do
allow the pop-up. How do I derive this from the arguments handed to the
event handler?
You do not need to know the URL as all you have to provide is a pointer
to an instance of TCppWebBrowser that should display the new page.
So you could instantiate a new form (containing a TCppWebBrowser) here
TForm1 *Form1 = new TForm1(0,false,0,0);
*ppDisp = Form1->CppWebBrowser1->Application;
Hans.
 

Re:CppWebBrowser OnNewWindow2 event handling

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
You do not need to know the URL as all you have to provide is a pointer
to an instance of TCppWebBrowser that should display the new page.
So you could instantiate a new form (containing a TCppWebBrowser) here
TForm1 *Form1 = new TForm1(0,false,0,0);
*ppDisp = Form1->CppWebBrowser1->Application;
Thanks, Hans. However, I am not letting the pop-up launch normally (for
several reasons) in another IE instance. I want to control the app launching
the URL. That is why I need the URL. I have seen a solution that invovles
letting the instance start, but grab the URL and cancel the navigation
inside the OnBeforeNavigate event, but I don't like that solution. Is there
any way of getting the intended URL from the LPDISPATCH parameter?
--
Mark Jacobs
www.jacobsm.com
 

{smallsort}

Re:CppWebBrowser OnNewWindow2 event handling

Mark Jacobs wrote:
Quote
...I want to control the app launching
the URL. That is why I need the URL. I have seen a solution that invovles
letting the instance start, but grab the URL and cancel the navigation
inside the OnBeforeNavigate event, but I don't like that solution. Is there
any way of getting the intended URL from the LPDISPATCH parameter?
At the moment I don't know. What I found was a thread with Subject:
Getting Target in NewWindow2
<quote>
Another approach I've tried is capturing DWebBrowserEvent::NewWindow
instead. Since that handler, unlike NewWindow2, gets the target, as
well as the URL, I could just do cancel the request and create the
window myself. But that breaks the window relations within the
scripting engine, so it was a less than satisfactory solution.
</quote>
Now NewWindow is not public. But maybe you can make a class that
makes it public.
By the way: You are not generating the html yourself I suppose.
Hans.
 

Re:CppWebBrowser OnNewWindow2 event handling

Hans Galema wrote:
Quote
<quote>
Another approach I've tried is capturing DWebBrowserEvent::NewWindow
instead. Since that handler, unlike NewWindow2, gets the target, as
well as the URL, I could just do cancel the request and create the
window myself. But that breaks the window relations within the
scripting engine, so it was a less than satisfactory solution.
</quote>

Now NewWindow is not public. But maybe you can make a class that
makes it public.

By the way: You are not generating the html yourself I suppose.
Again, many thanks. Some good ideas here. But it does seem as if M$ have
sabotaged a really useful pop-up blocker event, and replaced it with something
much harder to work with!
I have dabbled with the header file shdocvw_ocx.h but I cannot get the
OnNewWindow event from TCppWebBrowser_V1 into the TCppWebBrowser class
definition. Any ideas?
--
-
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
 

Re:CppWebBrowser OnNewWindow2 event handling

Mark Jacobs wrote:
Quote
Hans Galema wrote:
>By the way: You are not generating the html yourself I suppose.
???
Hans.
 

Re:CppWebBrowser OnNewWindow2 event handling

Hans Galema wrote:
Quote
Mark Jacobs wrote:
>Hans Galema wrote:

>>By the way: You are not generating the html yourself I suppose.

???
No, it is just a simple web browser.
--
-
Mark Jacobs
DK Computing
www.dkcomputing.co.uk