Hosting WebBrowser control, NewWindow3, and window.opener problems

G

Guest

Greetings,

Forgive me if this is in the wrong newsgroup...

I have a C# app that has a form that hosts the IE WebBrowser control. I've
added an event handler for the NewWindow3 event so that when a new window is
requested, I can created my own form with the browser control and display the
requested URL.

The problem is that new HTML has javascript code that uses window.opener. In
standalone IE, this works fine. But under my application, nothing happens. I
need this to happen in my app.

Does anyone know how to associate a new browser control to a an existing one
(opener-child)?


I have code, sample html, that I can post up here if anyone needs more info.

Tia...


Neil
 
R

Rob Parsons

This is a hard one to answer. All the searching I have done has not turned
up a definitive answer. Seems that window.opener is a javascript thing
However I did find this interesting snippet..

window.opener.location = url

which seems to suggest that you could program the child window opener not by
a hwnd but by the location url of the parent. ie either by

using mshtml.dll to set the window.opener.location value to the url address
of the parent window ( I am not sure if mshtml exposes the opener but it
would seem logical that it would)

or

on creating the new window insert a snippet of code in the document say
beforeBegin that does the javascript assignment above.

I haven't done it but I would suggest that in your project you make a
reference to mshtml and the search the Object Browser for the opener objects
properties.

I see also that you refer to the 'NewWindow3' event... Is this a typo? or
did you mean NewWindow2 event... I am using Win2000 and v6 sp3 IE... If
there is a NewWindow3 event then it is probably only for the XP versions of
IE.. so becareful if you want to deploy to other platforms.

I just opened mshtml in an object browser and yep the opener object is
referenced as a property of a HTMLWindow2 object.

As a parting thought, you might like to try when you create the new window
to set its Parent property to the hwnd of the browser ctrl that is creating
it? Maybe somehow that will set the opener property in the child browser?

Good luck... don't know. Might be back to the old drawing board.
 
G

Guest

Thanks for the response. I had asked the same question on the developer
newsgroups and a response was submitted after I had figured out what I was
doing wrong. It turns out the NewWindow2/NewWindow3 events should only create
the new browser window and pass back a reference to the new browser window's
application object. Nothing more. What I was doing wrong was forcing a
navigate to occur. When you do this, the browser control loads a new page and
clears out the window.opener assignment that the browser control had
originally set up.

And as a FYI, the NewWindow3 event came out with XP SP2. So its not a typo.
I'm not worried where the app is deployed since its an internal app and we
have full control over the deployment environment (which btw is Windows 2003
w/ SP1). We've verified that this API call is available and works correctly.

You mention that setting Parent property may get the job done, but I think
that property actually refers to the Browser Control's hosting window. So if
I were to change it, the control could disapper window the form it should be
on.


Thanks for taking the time to answer.

Neil
 
Joined
Mar 19, 2008
Messages
1
Reaction score
0
Problem in maintaining parent child relationship in webbrowser control

Hi
I am using web browser control, i could open all the URLs but when i am opening a popup window, if click on yes or no button it is throwing an error saying
"Doucumnet.opener is null or not an object"
I know why this error is coming becuase it could not find the parent page which initated the popup.

kindly let me know the solution if any one knows

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top