Solved

Restricting Navigation to  within my Frames using WebBrowser2 ActiveX control

Posted on 1998-06-04
7
268 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 93
noX challenge 17 93
How to convert MFC::CString to UTF8 wchar_t* 10 150
Excel file not created as expected 7 51
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

22 Experts available now in Live!

Get 1:1 Help Now