-1

我正在使用 WP7 WebBrowser 控件。在这个页面上我有一个超链接。这个链接来自网络服务。我想在我的应用程序代码后面(即在 C# 中)处理该超链接的单击事件。我想在此超链接单击事件上显示另一个 Web 浏览器控件

有没有办法让 WebBrowser 控件处理点击事件?

4

1 回答 1

0

If i understand you, you want to intercept the onClick event in your first WB control (call this WB1), and open that page up (when the hyperlink is clicked) in another WB control (call this WB2)?

There are several ways you can do this, is this link set to open up in a new window? If so, you can intercept the NewWindow2 event is WB1 and run the following code in the NewWindow2 event of WB1...

Set pDisp = WB2.object

(it may be ppDisp instead of pDisp, but it will show up when your event is auto generated, choose whichever object name shows up in your arguments list).

Otherwise, you can intercept this request during BeforeNavigate2 event of the WB1 event, check the URL property if it is the link you're interested in, and if so, cancel the current request and reissue a new one as below... (in the WB1 BN2 event)...

Cancel = True ' This cancels the request
WB2.Navigate2 URL, , "YourWB2sDocumentNameOrTargetFrameNameGoesHere"

Second line of code just reissues the request.

Of course, the YourWB2sDocumentNameOrTargetFrameNameGoesHere is the TargetFrameName (or the frame or document name of the top level document, or any iframe, in your WB2 control/window). This can usually be found in the BODY tags name= property, but you don't even need to do this if all you want is to load it as the top level document in WB2... if you just want to load it as the parent top level document in WB2, just do this...

Cancel = True
WB2.Navigate2 URL

By referencing WB2 it will just send the same URL request to WB2 window after cancelling WB1 request.

Let me know if you need more help and let me know how you get along.

于 2012-08-31T11:37:21.020 回答