Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Window.Open params unreliable

99 views
Skip to first unread message

Kyle Fields

unread,
Jun 21, 2002, 5:55:15 PM6/21/02
to
When opening a new window and resizing it to match the Javascript
window.open() parameters, the width and height values work on some web
sites -- but not all.

On some sites the new browser window is created to the correct size. On
other sites, the width and height values are bogus or even negative.

Here is my code to handle resizing the browser in the OnBeforeNavigate2()
event (written in MFC 6.0):

void CBrowser::OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT
FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT
FAR* Headers, BOOL FAR* Cancel)
{
IWebBrowser2* pWB = NULL;
long newWidth, newHeight;

HRESULT hr = pDisp->QueryInterface( IID_IWebBrowser2, (void**)&pWB );
if (SUCCEEDED(hr))
{
pWB->get_Width(&newWidth); // get window.open, width parameter
pWB->get_Height(&newHeight); // get window.open, height paramter
}
......

On some sites, the newWidth and newHeight values are wrong or even negative
values. For example, the site: www.goped.com/html-products/sport-info.shtml
then click 'View Specs' produces a width of -40 and height of -62 (it should
be 400 x 300). Other web sites get the window size correctly.

Thanks for any help.


Igor Tandetnik

unread,
Jun 21, 2002, 6:09:52 PM6/21/02
to
Are you hosting WebBrowser control and handling NewWindow2 to create
your own form with another WebBrowser? IE5.5 and above fire
WindowSetWidth and WindowSetHeight events. For earlier versions, see KB
Article Q259963 "HOWTO: Obtain Width and Height Supplied to Window.open
Inside the Visual C++ WebBrowser Host"
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Kyle Fields" <kfi...@pacbell.net> wrote in message
news:uRbR34WGCHA.2740@tkmsftngp13...

Kyle Fields

unread,
Jun 21, 2002, 7:03:38 PM6/21/02
to
Igor,

To answer your question, I am handling NewWindow2 to create a new dialog
with another WebBrowser control -- all that works fine.

I tried handling WindowSetWidth and WindowSetHeight, but that produces the
same incorrect results (the Width and Height params passed to the event
handlers are bogus or negative values).

This only occurs on some sites (the goped.com site listed below) -- other
sites work OK.

Thanks for you help -- any ideas?

-Kyle

"Igor Tandetnik" <itand...@whenu.com> wrote in message
news:OuJWDBXGCHA.2296@tkmsftngp12...

Igor Tandetnik

unread,
Jun 24, 2002, 5:08:56 PM6/24/02
to
Well, I have just built quick and dirty sample which does nothing but
log WindowSetWidth and WindowSetHeight. Each event is fired once, with
correct parameters (400 and 300 correspondingly). I never see negative
values there.

I guess you confuse the control when you are sizing it at the same time
it is sizing itself. I suggest you sink those events and remember the
values the control sends to you, but do not resize it in response to
those events. Wait until you receive OnVisible(TRUE), then resize your
form using the coordinates you obtained earlier.


--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Kyle Fields" <kfi...@pacbell.net> wrote in message

news:OJSTEfXGCHA.1600@tkmsftngp13...

0 new messages