Solved

Restricting Navigation to  within my Frames using WebBrowser2 ActiveX control

Posted on 1998-06-04
7
267 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:MuraliKrishna
  • 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:MuraliKrishna
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:MuraliKrishna
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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:MuraliKrishna
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:MuraliKrishna
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now