Solved

Restricting Navigation to  within my Frames using WebBrowser2 ActiveX control

Posted on 1998-06-04
7
269 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
Named range not carried over 10 63
Define unique primary key 9 92
notReplace  challenge 53 131
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

809 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