Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Author |
Message |
Murali Krishna Devarakond #1 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
I have an MFC App hosting the IE 4.01 WebBrowser Control in the View. When an HTML Page is loaded, can I override a function (method/ property)? For example, here's one that I would definitely like to override: <script language="JavaScript"> <!-- if (window != window.top) top.location.href = CurrentPage //--> </script> Can I implement some Interface in my app that allows me to disable the above function call? The above script ensures that the current page loads in the top-most browser window, and not in any frame. I WANT to load all pages in a frame within the Browser Control in my app. Thanks for your help! Murali Krishna Devarakonda
|
Tue, 13 Feb 2001 03:00:00 GMT |
|
 |
Jerry Mea #2 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Quote: >> For example, here's one that I would definitely like to override:
<script language="JavaScript"> <!-- if (window != window.top) top.location.href = CurrentPage //--> </script> << Well, you don't have to use it on your own pages ... and if it's someone else's page, surely they've used this because they don't want their page showing up in your frameset? J.
|
Tue, 13 Feb 2001 03:00:00 GMT |
|
 |
Murali Krishna Devarakond #3 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Jerry, That's no help at all. You missed my point. I have an app that loads a default HTML page that has to remain in place all the time. Among others, it consists of a main frame, within which any typed url or linked page needs to be displayed. The BeforeNavigate2 handler of the WebBrowser control is the place to do this, by canceling the current navigation and calling Navigate(2) with the TargetFrame specified. And this works fine for except when the script I've mentioned exists, which results in a tug-of-war. I need I need to implement a COM scripting interface such as IActiveScriptSite, and override the above script, either by disabling or tricking it. I am hoping that someone out there is already familiar with this scenario, and probably has already done what I'm trying to do. If so, I need suggestions about how to go about it, and any potential problems. Thanks, Murali Krishna Devarakonda
|
Tue, 13 Feb 2001 03:00:00 GMT |
|
 |
Kenneth Kasajia #4 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Jerry, Explain to me why people like you post these types of responses? This is not a philosophical discussion, yet a technical one. Don't worry about why he wants to do what he wants to do. If you know of a way *how*, then post, otherwise, don't bother -- itsn't helping anyone. Quote:
>>> For example, here's one that I would definitely like to override: > <script language="JavaScript"> > <!-- > if (window != window.top) > top.location.href = CurrentPage > //--> > </script> ><< >Well, you don't have to use it on your own pages ... and if it's someone >else's page, surely they've used this because they don't want their page >showing up in your frameset? >J.
|
Sun, 18 Feb 2001 03:00:00 GMT |
|
 |
Jerry Mea #5 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Quote: >> Jerry,
Explain to me why people like you post these types of responses? << Bad temper, mostly.
|
Mon, 19 Feb 2001 03:00:00 GMT |
|
 |
Captain Cerebru #6 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Hi Murali, I was thinking a while on your problem. Sorry, you're going wrong way. IActiveScript* interfaces won't help you. There is no way to control script statement sequences; there is simply nothing to override with IActiveScript*. The only way would be to develop your own full-featured yet compatible Scripting Engine (say JScript) from scratch and replace standard one. Sure, this is not real, and even if you did, this is not the case. Consider this hypothetical script: var mytop = window.top ...(later) if ( window !== mytop ) mytop.location.href = <CurrentPage> You should have done a very complex logic to trace all aliases and take all possible cases into account. Your mentioned script is likely the only occurred to you so far. Do you observe all other possible gotchas? More, altering a script could harm a logic of whole page. How could your issue be resolved? As I understand, using BeforeNavigate2/Navigate2 technique leads to endless loop because of the darn script. I see virtually no good solution with frames. The only way seems to make your frame a real topmost browser. As you host WebBrowser in an MFC View, you might use Splitter to divide your view into two parts, and host two independent browsers. One would be "Main", another one - "Target". It's easy to place a reference to "Target" into "Main" object model, if needed, so you could access "Target" content from "Main" as though it were a frame. From user point of view, there would be no difference between two browsers in Splitter and one browser with two frames. Regards, Captain Cerebrum Innovative stuff for IE4 and HTML Help authoring http://www.meadroid.com/wpm/ FREE ScriptX: Dynamic Event Binding http://www.meadroid.com/scriptx
|
Mon, 19 Feb 2001 03:00:00 GMT |
|
 |
Captain Cerebru #7 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Btw, some aspects of frame using (not technical though) are discussed at: http://www.microsoft.com/sitebuilder/magazine/site.asp So, expect quite a few pages to make a trouble for you. This is another vote for two separate browsers :-) -cap.
|
Mon, 19 Feb 2001 03:00:00 GMT |
|
 |
Kenneth Kasajia #8 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
That's a bit drastic. I would think that before you write your own JScript compatible scripting engine, you could at least try to replace the particular piece of code in question right in the HTML file. You could trap the browser before it interprets the HTML, grab the HTML text, programatically find the script, modify it, and stuff back in the browser. Quote:
>Hi Murali, >I was thinking a while on your problem. Sorry, you're going wrong way. >IActiveScript* interfaces won't help you. There is no way to control script >statement sequences; there is simply nothing to override with IActiveScript*. >The only way would be to develop your own full-featured yet compatible Scripting >Engine (say JScript) from scratch and replace standard one. Sure, this is not >real, and even if you did, this is not the case. Consider this hypothetical >script: >var mytop = window.top >...(later) >if ( window !== mytop ) mytop.location.href = <CurrentPage> >You should have done a very complex logic to trace all aliases and take all >possible cases into account. Your mentioned script is likely the only occurred >to you so far. Do you observe all other possible gotchas? More, altering a >script could harm a logic of whole page. >How could your issue be resolved? As I understand, using >BeforeNavigate2/Navigate2 technique leads to endless loop because of the darn >script. I see virtually no good solution with frames. The only way seems to make >your frame a real topmost browser. >As you host WebBrowser in an MFC View, you might use Splitter to divide your >view into two parts, and host two independent browsers. One would be "Main", >another one - "Target". It's easy to place a reference to "Target" into "Main" >object model, if needed, so you could access "Target" content from "Main" as >though it were a frame. From user point of view, there would be no difference >between two browsers in Splitter and one browser with two frames. >Regards, >Captain Cerebrum >Innovative stuff for IE4 and HTML Help authoring >http://www.meadroid.com/wpm/ >FREE ScriptX: Dynamic Event Binding >http://www.meadroid.com/scriptx
|
Mon, 19 Feb 2001 03:00:00 GMT |
|
 |
Captain Cerebru #9 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
That's a bit drastic. I would think that before you write your own JScript compatible scripting engine, you could at least try to replace the particular piece of code in question right in the HTML file. You could trap the browser before it interprets the HTML, grab the HTML text, programatically find the script, modify it, and stuff back in the browser. << I'd strictly discourage writing own JScript/ VBScript! It surely would be forces spent in vain. From the other end, filtering out scripts like what Murali doesn't like could be very complex if not impossible, because of variable alisasing and other unpredictable script's author logic. And again, altering a page's script could break the page behavior. I'd stay with solution I've proposed. -cap. Quote:
>Hi Murali, >I was thinking a while on your problem. Sorry, you're going wrong way. >IActiveScript* interfaces won't help you. There is no way to control script >statement sequences; there is simply nothing to override with IActiveScript*. >The only way would be to develop your own full-featured yet compatible Scripting >Engine (say JScript) from scratch and replace standard one. Sure, this is not >real, and even if you did, this is not the case. Consider this hypothetical >script: >var mytop = window.top >...(later) >if ( window !== mytop ) mytop.location.href = <CurrentPage> >You should have done a very complex logic to trace all aliases and take all >possible cases into account. Your mentioned script is likely the only occurred >to you so far. Do you observe all other possible gotchas? More, altering a >script could harm a logic of whole page. >How could your issue be resolved? As I understand, using >BeforeNavigate2/Navigate2 technique leads to endless loop because of the darn >script. I see virtually no good solution with frames. The only way seems to make >your frame a real topmost browser. >As you host WebBrowser in an MFC View, you might use Splitter to divide your >view into two parts, and host two independent browsers. One would be "Main", >another one - "Target". It's easy to place a reference to "Target" into "Main" >object model, if needed, so you could access "Target" content from "Main" as >though it were a frame. From user point of view, there would be no difference >between two browsers in Splitter and one browser with two frames. >Regards, >Captain Cerebrum >Innovative stuff for IE4 and HTML Help authoring >http://www.meadroid.com/wpm/ >FREE ScriptX: Dynamic Event Binding >http://www.meadroid.com/scriptx
|
Mon, 19 Feb 2001 03:00:00 GMT |
|
 |
Captain Cerebru #10 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
Why do I get the feeling that there MUST be some way for My App hosting the WebBrowser control hosting MSHTML.dll hosting the Scripting Engine to somehow accomplish my goal of loading any page into the desired frame? << I don't know why do you :) I have certain good experience hosting both WebBrowser and standalone Scripting Engine, and I don't have such a feeling. Take as given that you're unable to selectively override script snippets with IActiveScript* family. As I said, the only way is to develop your own engines (maybe as wrapper delegating to JScript/VBScript) and substitute them in registry. This is an ugly way. And I've tried to explain more natural reason in this thread. Did you read mentioned Para-Sites article? Of course, it's up to you what direction to follow. I'm just going to save your development time.
2) Do you happen to know how I can get access to the type library of JScript and VBScript, if they exist at all? << IActiveScript* are not Automation compatible, hence there is no typelib for them. They're defined in ActivScp.Idl/h from Platfrom SDK. Regards, -cap.
|
Tue, 20 Feb 2001 03:00:00 GMT |
|
 |
Captain Cerebru #11 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
oops, sorry, mispost... -cap.
|
Tue, 20 Feb 2001 03:00:00 GMT |
|
 |
#12 / 13
|
 Overrriding JScript (or any Script) in MFC App Hosting WebBrowser Control
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
|
|