Hello, I have 2 WebBrowsers inside my Windows Form. I use the first as a small userbar, ie I put links and rich content in it. The second one is the "real thing", ie it displays the main content, webpages and so on.
Here comes the problem: when the user clicks a link in the 1st WebBrowser, I want to open the corresponding URL in the 2nd WebBrowser. How to do this?
I tried doing <a href="webpage.htm" target="WebBrowser2">Click here</a> but it's not working.
thanks!
Last edited by BrightSoul; Jun 22nd, 2006 at 08:49 AM.
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.
I've never used a WebBrowser control except to answer other people's questions, but here's the methodology I used to get the answer you need.
First of all I need to know when the user clicks a link in the first WebBrowser. That means I'm going to have to handle an event. I go to the member listing for the WebBrowser in the MSDN library and see what events are available. After a bit of investigation I find that the Navigating event is raised before the WebBrowser navigates to a new location. A little more investigation reveals that the WebBrowserNavigatingEventArgs object passed to the 'e' argument to the Navigating event handler has a Url property and a Cancel property. This means that you can get the URL to which the WebBrowser was going to navigate, then cancel that navigation. You now use the URL you retrieved in the second WebBrowser control.
That's the sort of thing you need to do. You think of the class you are using and the type of member you would need. If you need to know something about the object it will be a property. If you need the object to do something it will a method. If you need to know when something happens in or to the object then it will be an event. You then go to the MSDN library and look at what members the class has of that type. You read the name and description of each one and when you find one that sounds likely you read the detail about it. It doesn't hurt to have at least a cursory look at the overview and member listing for every class you're using from the get-go, before you even write any code at all. That's how I solve at least 95% of the problems I have and it's how I can answer questions like this that I've had no previous experience with.
oh, thanks for the nice explaination !
The Navigating event will do the trick.
However, I was also interested in finding out why my WebBrowser whose window.name equals "test" wouldn't naturally receive the input from links that have target="test".
Additionally, set the RegisterAsBrowser property to true. This setting causes the new WebBrowser control to participate in window-name resolution
Unfortunately, RegisterAsBrowser is a proprerty of the underlying ActiveX control which is not exposed by the NET 2.0 WebBrowser.
Then I found this.
Thanks to this article I was then able to set that property via the IWebBrowser2 interface that's exposing some unsafe stuff. I attach the assembly I made out of it, if anyone will ever be interested.
The Navigating event was, of course, simpler, but I couldn't use it to POST data from a WebBrowser to the other, if I wanted.
Last edited by BrightSoul; Jun 22nd, 2006 at 09:05 AM.
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.
I'd suggest brushing up on your HTML as target=BrowserName is not valid HTML. It doesn't exist so I'm not sure where you found it or why you're trying to use it.
The target attribute only accepts 4 things: _blank, _parent, _self and _top. See here for more information.
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
I'd suggest brushing up on your HTML as target=BrowserName is not valid HTML.
What the heck are you talking about?
target="whatever" complies perfectly with the XHTML 1.0 Transitional standard and it's even supported by the W3Consortium, of course. http://www.w3.org/TR/REC-html40/pres...ml#adef-target
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.
What the heck are you talking about?
target="whatever" complies perfectly with the XHTML 1.0 Transitional standard and it's even supported by the W3Consortium, of course. http://www.w3.org/TR/REC-html40/pres...ml#adef-target
Did you read the information on the link? It allows it to link to another frame but not other web browsers. target="whatever" would have to be a frame name.
I'm not sure why it's not listed on the w3school website (what you posted).
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
and that's exactly what I'm doing. I'm navigating a page in the frame displayed in webBrowser2 by clicking a link in the frame displayed in webBrowser1.
When I said:
I tried doing <a href="webpage.htm" target="WebBrowser2">Click here</a> but it's not working.
it was because I thought that the frame in WebBrowser2 would automatically inherit its container name. I didn't mean to target the WebBrowser control itself.
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.
and that's exactly what I'm doing. I'm navigating a page in the frame displayed in webBrowser2 by clicking a link in the frame displayed in webBrowser1.
Again, you can't do that. HTML doesn't work that way. It allows you to link to another frame but not another frame in another web browser.
You can have multiple frames on one page, which is where you'd use that. Though, honestly you should avoid linking to frames anyway (actually, you should try to stay away from using any frames as they're not needed).
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
If any target attribute refers to an unknown frame F, the user agent should create a new window and frame, assign the name F to the frame, and load the resource designated by the element in the new frame.
new window means new webbrowser, no arguing about it.
This proves that targeting a frame in another webbrowser is possible and allowed. End.
Last edited by BrightSoul; Jun 24th, 2006 at 05:40 PM.
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.
new window means new webbrowser, no arguing about it.
This proves that targeting a frame in another webbrowser is possible and allowed. End.
Ugh.... listen, that doesn't prove that targetting a frame in another web browser is possible via HTML. It isn't. What that proves is that it can create a new window (like a target=_blank) but it loads the resources within that window via a frame.
Again, you CANNOT target a frame in one web browser to another frame in another web browser via only HTML. You can't even do it with JavaScript. Think of is as passing arguements to a web browser (much like you'd do in an application).
If you feel you're so right in this, then create a web page that can do this.
Misconstruing the W3C's guidelines just to try to prove me wrong isn't going to help you in anyway.
I would also like to add that a new window does not mean a new web browser. Another instance of the same web browser, maybe (Opera and possibly others use the same instance but can create multiple windows).
Last edited by Kasracer; Jun 25th, 2006 at 07:49 PM.
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
If you feel you're so right in this, then create a web page that can do this.
I'm already doing it and it's working! Look, maybe we just have a problem of communication here. English is not my first language so this could be the issue.
Originally Posted by kasracer
I would also like to add that a new window does not mean a new web browser. Another instance of the same web browser, maybe (Opera and possibly others use the same instance but can create multiple windows).
Of course! I don't expect to navigate a page in IE, click a link, and open the consequent page on Mozilla. Of course I was referring to multiple instances of the same User Agent.
With the word "WebBrowser" I mean the "WebBrowser control". More "WebBrowsers" = Multiple instances of the Internet Explorer activex control.
Oh my, is this gonna last forever?
Last edited by BrightSoul; Jun 26th, 2006 at 12:34 PM.
- mo! I said MOOOOOOO!!
- ...yep, that's a cow, alright.