• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

Restricting Navigation to within my Frames using WebBrowser2 ActiveX control

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
Murali Devarakonda
Asked:
Murali Devarakonda
  • 4
  • 3
1 Solution
 
chensuCommented:
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
 
Murali Devarakonda4WeekStartup.guruAuthor Commented:
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
 
Murali Devarakonda4WeekStartup.guruAuthor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
chensuCommented:
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
 
Murali Devarakonda4WeekStartup.guruAuthor Commented:
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
 
chensuCommented:
It is OK for me.
0
 
Murali Devarakonda4WeekStartup.guruAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now