Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: 21 Feb 2007 13:05:39 -0800,    group: microsoft.public.inetsdk.programming.webbrowser_ctl        back       


Cannot get frames in IHTMLDocument2 when first navigating to a page with iframes   
I'm trying to detect whether or not a specific request is being made
by an iframe that is hidden.

Heres my test case:

<html>
<body>
<iframe style="visibility: hidden" src="http://foo.html></iframe>
<span style="display: none"><iframe src="http://bar.html"></iframe>
</body>
</html>

I've sinked the DWebBrowserEvents2 interface and am using
BeforeNavigate2. The problem is, is that when I attempt to access the
frames attribute of the IHTMLDocument2 of the page containing the
iframe, that collection always has a length of 0, so I am unable to
check whether the URL I've received is from the src attribute of an
iframe.

I'm trying to access the IHTMLDocument2 containing the iframe by
walking up the parent heirarchy of the IWebBrowser2 interface I get
from the pDisp parameter in BeforeNavigate2.

The collection seems to become available after DocumentComplete fires
for the page containing the iframes happens. This is too late, as I
need to take some action before the request even gets sent to the
server.

The collection also seems to work fine if, after the page loads, some
javascript inserts new iframe nodes (probably because the page
containing the iframe has already loaded)

Trying to access the body or innerHTML attributes of the document also
fails until the final DocumentComplete fires.

Is there another way to perform this check or to get the
IHTMLDocument2 interface with the DOM properly initialized?

Just being able to verify that the IWebBrowser2 I get from QI'ing the
pDisp parameter in BeforeNavigate2 comes from a IHTMLIFrameElement
would in theory work (I suppose) but I'm don't know how, or if thats
possible either.

Any help would be most appreciated.
date: 21 Feb 2007 13:05:39 -0800   author:   unknown

Re: Cannot get frames in IHTMLDocument2 when first navigating to a page with iframes   
jmpinchot@gmail.com wrote:
> I'm trying to detect whether or not a specific request is being made
> by an iframe that is hidden.
>
> Heres my test case:
>
> <html>
> <body>
> <iframe style="visibility: hidden" src="http://foo.html></iframe>
> <span style="display: none"><iframe src="http://bar.html"></iframe>
> </body>
> </html>
>
> I've sinked the DWebBrowserEvents2 interface and am using
> BeforeNavigate2. The problem is, is that when I attempt to access the
> frames attribute of the IHTMLDocument2 of the page containing the
> iframe, that collection always has a length of 0, so I am unable to
> check whether the URL I've received is from the src attribute of an
> iframe.

BeforeNavigate2 event comes with IDispatch parameter that refers to the 
WebBrowser object firing the event. Compare it to IWebBrowser2 pointer 
of the top-level WebBrowser object: if it doesn't match, the event comes 
from a frame or iframe.

You must use COM identity comparison: explicitly query both pointers for 
IUnknown, then compare resulting IUnknown pointers. If you use ATL, see 
CComPtr::IsEqualObject.

> I'm trying to access the IHTMLDocument2 containing the iframe by
> walking up the parent heirarchy of the IWebBrowser2 interface I get
> from the pDisp parameter in BeforeNavigate2.

If I recall correctly, IWebBrowser2::get_Parent returns containing 
document when called from a frame or iframe.

> The collection seems to become available after DocumentComplete fires
> for the page containing the iframes happens. This is too late, as I
> need to take some action before the request even gets sent to the
> server.

What do you need the collection for?
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Wed, 21 Feb 2007 16:18:28 -0500   author:   Igor Tandetnik

Re: Cannot get frames in IHTMLDocument2 when first navigating to a page with iframes   
> What do you need the collection for?

I need a reference to the IHTMLIFrameElement that contains the
IWebBrowser2 so that I can then check the IHTMLStyle and
IHTMLCurrentStyle to verify whether or not its hidden (and possibly
walk up the DOM tree if visibility is set to "inherit"). I use the src
attribute of the iframe to compare with the value I get from the URL
parameter of BeforeNavigate2 to make sure that I check the correct
IHTMLIFrameElement.

Thanks for your help.
date: 21 Feb 2007 13:43:41 -0800   author:   unknown

Re: Cannot get frames in IHTMLDocument2 when first navigating to a page with iframes   
jmpinchot@gmail.com wrote:
>> What do you need the collection for?
>
> I need a reference to the IHTMLIFrameElement that contains the
> IWebBrowser2 so that I can then check the IHTMLStyle and
> IHTMLCurrentStyle to verify whether or not its hidden

See if IWebBrowser::get_Width, get_Height help (I would expect a hidden 
iframe to have zero size).
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Wed, 21 Feb 2007 16:57:34 -0500   author:   Igor Tandetnik

Re: Cannot get frames in IHTMLDocument2 when first navigating to a page with iframes   
> See if IWebBrowser::get_Width, get_Height help (I would expect a hidden
> iframe to have zero size).

It looks as though every IFrame, hidden or not, has a height and width
of 0 in BeforeNavigate2. Furthermore if a redirect occurs within one
of those hidden iframes its height and width are not 0.

Thanks again for your help.
date: 21 Feb 2007 14:19:39 -0800   author:   unknown

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us