Google Answers Logo
View Question
 
Q: Need Visual C++ Sample of Controlling the Browser ( No Answer,   5 Comments )
Question  
Subject: Need Visual C++ Sample of Controlling the Browser
Category: Computers > Programming
Asked by: cpriest-ga
List Price: $2.00
Posted: 26 Mar 2004 08:12 PST
Expires: 25 Apr 2004 09:12 PDT
Question ID: 320757
I want to have a working Visual C++ 6.0 sample code which shows how I
can intercept and modify HTML code from a browser window after it has
been navigated but before it has been shown or processed.  More
specifically I want to be able to modify <SCRIPT> elements as I see
fit before they are executed in any way by the browser.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Need Visual C++ Sample of Controlling the Browser
From: scoobiesnack-ga on 29 Mar 2004 16:55 PST
 
You need to look into ActiveX for this.
Subject: Re: Need Visual C++ Sample of Controlling the Browser
From: cpriest-ga on 29 Mar 2004 18:59 PST
 
Any chance you could be a bit more specific?  Do I need to write an
object which somehow gets loaded with the page?  Would I set that up
with an OnLoad command?  How can I do that before the page is
processed?  Any other hints, re: activeX ?
Subject: Re: Need Visual C++ Sample of Controlling the Browser
From: rerdavies-ga on 30 Mar 2004 21:45 PST
 
Can't be done. Not directly in a browser, anyway.

If the browser is loading the page, you can arrange to get
notifications at various points during the load. However, elements in
the page are added asynchrounously as the browser receives them, and
there's no notification you can subscribe to in order to find out when
individual elements are added.

You could, for example, attach to the body.onLoad event, but, by the
time this event fires, all script blocks will have been parsed and
loaded, and any global-scope code will have already executed.

You could fetch the page yourself (using WinHTTP or WinINET APIs),
modify it, and then write the result into the browser using
document.write() on an empty page.

To call functions like document.write(), you will need to obtain the
root DOM object, and then procede to make calls on that object using
the IDispatch (or IDispatchEx) interface.
Subject: Re: Need Visual C++ Sample of Controlling the Browser
From: rerdavies-ga on 30 Mar 2004 21:49 PST
 
Oh. And you can also attach to nagivation events too. So. The plot summary:

Catch navigation events. Intercept them and cancel them.

Take the intercepted URL, load the contents yourself. 

Clear the document. 

Write the modified contents using document.write().

There are other challenges: e.g. do you want to preserve POSTed URLs
as well as GET-ed URLs? (i.e. do you want forms processing to work
properly). This is solvable, but will probably require a fair bit of
work.
Subject: Re: Need Visual C++ Sample of Controlling the Browser
From: cpriest-ga on 31 Mar 2004 06:42 PST
 
Thank you so much, at least I can stop beating my head against the
wall trying to control IE, I guess I'll consider doing what you've
suggested, I write a search toolbar with the added feature of
controlling popups but its not a perfect world, primarily because I
don't know the source of NewWindow2() calls, but also there are new
methods of causing popups that don't get caught by NewWindow2().

Thanks mucho!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy