Re: Detect if a new window has been spawn by a user click or not
Hello Stefano,
I am currently having the same problem but i almost got the solution, here큦 what i did.
Normally when the user clicks on a window.open() html link a new pop up window will appear in the Internet Explorer. To catch this use the OnNewWindow2 event from the TWebBrowser component and do something like this:
procedure TfrmWindow.wbBrowserNewWindow2(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool); var frmPopUp: TfrmPopUp; begin Application.CreateForm(TfrmPopUp, frmPopUp); frmPopUp.wbPopUp.RegisterAsBrowser := true; frmPopUp.Visible := true; ppDisp := frmPopUp.wbPopUp.Application; end;
This code will open new pop up windows on a form i already designed called frmPopUp, if you want to open pop up content in the same window maybe you can try this: (i dont know if it works!!)
procedure TfrmWindow.wbBrowserNewWindow2(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool); var frmPopUp: TfrmPopUp; begin self.wbBrowser.RegisterAsBrowser := true; ppDisp := self.wbBrowser.Application; end;
Note: wbBrowser is the name of the TWebBrowser component you are using in your main form.
Hope this works..
Bye --- In delphi-webbrowser@yahoogroups.com, "stefano_falda" wrote: > Hello, > is there a way to detect if a new window has been spawn by a user > click or not, because I want to redirect new windows from user clicks > to the current window and to cancel the automatic popups... > > Thank you > stefano
================================================================================
Re: onNewWindow2 and window.open
Hi,
Why do you need the extra parameters? If you create an instance off your own designed window (form) you can add toolbars, allow scrolling etc. Use onClientToHostWindow (TwebBrowser) to set the size of the window intended by the webpage designer.
cu Andries
--- In delphi-webbrowser@yahoogroups.com, "cgalavis" wrote: > Hi, > I want to implement a custom window to display popups, or anything > that requires a new window. For this a implement the onNewWindow2 > event, create an instance of my window, and assign it to the ppDisp > interface. This all works great, except that if the window is been > generated in response to a call to the window.open method, there are > extra parameters that indicate whether the toolbars are enabled, or > the whether window allows scrolling, predefine width and height, > etc... > > Is there a way to get this information so I can use it when creating > the instance of my window in the onNewWindow2 event? > > Regards, > > Carlos Galavis
==========================================================================
RE: [delphi-webbrowser] Differentiate between Link and Open
> I need to be able to tell whether a onNewWindow2 event is triggered > from clicking on a link (anchor) that has a target assigned, or from > a call to window.open. Any ideas?
You can detect if a user has clicked a link by implementing the
HTMLDocumentEvents2::onclick
com event. There's a full article with source code about doing this for a very full featured C++ Popup blocker at:
http://www.codeproject.com/atl/popupblocker2.asp?target=popup%7Cblocker
You'll need to use EventSinkImp from TechVanguards to get a com interface to HtmlDocumentEvents2:
http://www.techvanguards.com/products/eventsinkimp/
Hope it helps!
Brad Parks.
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.530 / Virus Database: 325 - Release Date: 10/22/2003
=========================================================================
Solved this problem. Solution was quite simple.
I place the following code in the tembeddedweb control.
procedure Tfrmpopup.iepopupDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); begin self.clientwidth := self.iepopup.width; // get window.open width and resize the form to match self.clientheight := self.iepopup.height; // get window.open.height and resize the form to match end;
-----Original Message----- From: Lucas Van Staden [mailto:LucasVS@...] Sent: 26 March 2003 03:42 To: delphi-webbrowser@yahoogroups.com Subject: [delphi-webbrowser] problems with popup window
Hi.
My application, which contains a tembeddedwb, display web pages that opens a popup window (top level ie window), and from that popup the user must be able to select a value to populate a input box in the parent window.
The popup winnow is opened with a simple JavaScript : window.open(bla bla bla) command, and in the popup window the click on the selected item is again handled by JavaScript : window.opener.searchform.company.value=(bla bla bla)
On most machines this causes a JavaScript error of 'Permission denied', but on some (including my own machine), it works fine. The problem is also not contained to a specific version of Windows.
I suspect the problem is that the new top level IE cannot see my embeddedwb browser as the parent, thus JavaScript cannot write to the opening parent window.
I have changed my program to open a new form that contains another tembeddedwb, and doing it that way works on all machines. (using onNewWindow2). The problem with this now is that I seem to have no control on the new created window size (the JavaScript open command send the desired height and width, as per normal JavaScript.
Any ideas on how I can fix either, as it does not matter if I open a top level ie window, or my own embedded popup window.
Regards Lucas van Staden
Software Developer ComparexAfrica +27 31 3674719 +27 82 4718063
[Non-text portions of this message have been removed]
Subscribe: delphi-webbrowser-subscribe@yahoogroups.com Unsubscribe: delphi-webbrowser-unsubscribe@yahoogroups.com List owner: delphi-webbrowser-owner@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
[Non-text portions of this message have been removed]
==============================================================================
Re: onNewWindow2 and window.open() parameters
--- In delphi-webbrowser@y..., "frizbog1" wrote: > It seems to be only a Frequently Asked Question (not a Frequently > Answered Question): > > While handling the onNewWindow2 event, how can I get the parameters > to a "window.open()" call in JavaScript (etc.)? If a link wants a > new browser popup window to be certain dimensions and not have > scrollbars, how can I honor this request? > > Arrrgghh!!!
Thought I'd pass on what I learned. I got an e-mail response saying that I needed to sink the DWebBrowserEvents2 events on the new browser window such as onToolBar", etc. When the new window is opened in onNewWindow2 in the original window and the ppDisp parameter is set to the ControlInterface of the new browser object, the DWebBrowserEvents2 interface on the new form gets these events to turn the toolbar on/off, set the form dimensions, etc.
I used Binh Ly's very cool EventSinkImp program (look at http://www.techvanguards.com to find it) to hook into the DWebBrowserEvents2 interface. It made a non-visible component wrapper around the interface that I could just drop on the form and start using. Very cool and I highly recommend it.
The only problem is that I haven't yet found an event to handle for the "scrollbar=yes" portion of the window.open() command. I guess that will come.
===============================================================================
덕분에 북마크 하나 늘렸습니다.
http://groups.yahoo.com/group/delphi-webbrowser/
구글링 잘하면 고수됩니다. |
|