Solved

Restricting Navigation to  within my Frames using WebBrowser2 ActiveX control

Posted on 1998-06-04
7
275 Views
Last Modified: 2013-11-19
I have an MFC/Visual C++ 5.0 SDI application, which uses the WebBrowser2 ActiveX control (IE4.0).
I'm implementing a custom browser, that hosts DHTML/HTML pages.

My app comes up with a default DHTML page, which consists of a "Main" frame,
and some other frames for control.
I want to be able to control all navigation, such that any "foreign" URL
will be showed in my "Main" frame.
I've written code in OnBeforeNavigate2Browser, which works alright when it's
from my URL, in which case I have a Target Frame specified in HTML. But it
doesn't work when there's no frame specified.

CString strTargetFrameName;

if ( ! TargetFrameName )
  TRACE( "ERROR: VARIANT FAR * TargetFrameName IS NULL!\n" );
if ( VT_BSTR != TargetFrameName->vt )
  TRACE( "ERROR: TargetFrameName->vt is not a VT_BSTR!\n" );

strTargetFrameName = TargetFrameName->bstrVal;
if ( TargetFrameName->bstrVal )
      TRACE( "IN:  Requested Target Frame = \"%s\".\n",
strTargetFrameName );
else
      TRACE( "IN:  No Target Frame Requested.\n" );

// Verify correct Frame name. Modify Frame name as per My rules.
CString strMyTargetFrameName = GetMyTargetFrameName( strTargetFrameName );

//Replace with the Frame
COleVariant oleVarFrameName( strMyTargetFrameName );
TargetFrameName = oleVarFrameName;

return;
____________________________________________________________________
You can send me email at Murali-KrishnaNOSPAM@Cheerful.com
Just remove the NOSPAM.

Thanks!
Murali Krishna Devarakonda
0
Comment
Question by:Murali Devarakonda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1316016
Please clarify:

If the hyperlink in the HTML page has the attribute "target=...", you are able to change it to your "Main" frame window in this event and it works. If it does not have the attribute "target=...", it still gets to the self frame window even though you specify the "Main" for TargetFrameName.

Is it?
0
 
LVL 1

Author Comment

by:Murali Devarakonda
ID: 1316017
No. You just made me realize that something even worse is happening- NOTHING!

It appears that my changing the value of the TargetFrameName in OnBeforeNavigate2Browser doesn't make any difference. It just follows the Frame name specified in the HTML.

Also, while I'm in one of my frames and I click on a URL that has no target specified in the HTML, it assumes the name of the current frame, and that's what I see in my OnBeforeNavigate2Browser. And my changing it doesn't seem to make any difference.

I also have a combo where I can type the name of a URL.
Any URL that I type there goes into my Main frame- that's what comes into OnBeforeNavigate2Browser.

As I understand it, my code in OnBeforeNavigate2Browser has no effect whatsoever. The only thing it's done for me is to make me understand the default routing of URLs into Frames!
0
 
LVL 1

Author Comment

by:Murali Devarakonda
ID: 1316018
I need to know how to control navigation of URLs into my Frames. Don't be mislead my OnBeforeNavigate2Browser handler, like I was.

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1316019
Take a look at the documentation about DWebBrowserEvents2::BeforeNavigate2. The TargetFrameName parameter is an in parameter, meaning that it does not affect the Browser's action.

You can set the Cancel parameter to TRUE to cancel the navigation operation and call IWebBrowser2::Navigate2 with the TargetFrameName set to "Main".
0
 
LVL 1

Author Comment

by:Murali Devarakonda
ID: 1316020
Thanks a lot! I guess I missed that cause it's mentioned only in the signature, and not in the description. I feel really silly.

However, do you agree that the question qualifies for only 50 points? Last night, in my frustration, I had increased it to 150, which is too high, as I realize with hindsight, after your answer. But the system doesn't let me reduce the points. I'll send mail to Linda requesting her to lower the points- provided you agree.

Thanks again.
   Murali Krishna Devarakonda
e: Murali-Krishna@Cheerful.com
0
 
LVL 23

Expert Comment

by:chensu
ID: 1316021
It is OK for me.
0
 
LVL 1

Author Comment

by:Murali Devarakonda
ID: 1316022
Thank you "Chensu". As Linda asked me to, I'm giving you the points. I really appreciate your help.

Hopefully, you won't be mad at me for reducing the points allocated. It's only a reflection of my opinion of the quality of the question- not your answer! Feel free to email me if you have any questions.

Thanks again.
Murali Devarakonda
e: Murali-Krishna@Cheerful.com

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 92
Expand data scrubbing tool 13 36
Prevent this page from creating additional dialogs. 3 725
sum13 challenge 24 135
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question