在 wp7 中处理 Web 浏览器链接事件 [英] handle web browser link event in wp7

查看:23
本文介绍了在 wp7 中处理 Web 浏览器链接事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using WP7 WebBrowser control . On this page I have a hyperlink.This link are came from web service. I want to handle the click event of that hyperlink in my application's code behind (i.e. in C#).And i want display another web browser controll on this hyperlink click event

WebBrowser 控件有处理点击事件的方法吗?

Is there are a way for the WebBrowser control to handle click events?

推荐答案

如果我理解你,你想在你的第一个 WB 控件中拦截 onClick 事件(调用这个 WB1),然后打开那个页面(当超链接是单击)在另一个 WB 控件中(称为 WB2)?

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)?

有几种方法可以做到这一点,此链接是否设置为在新窗口中打开?如果是这样,就可以截获NewWindow2事件为WB1,并在WB1的NewWindow2事件中运行以下代码...

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

(它可能是 ppDisp 而不是 pDisp,但它会在您的事件自动生成时显示,请选择您的参数列表中显示的任何对象名称).

(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).

否则,您可以在WB1事件的BeforeNavigate2事件期间拦截此请求,检查URL属性是否是您感兴趣的链接,如果是,则取消当前请求并重新发出新的请求,如下所示..(在WB1 BN2事件中)...

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.

当然,YourWB2sDocumentNameOrTargetFrameNameGoesHere 是 TargetFrameName(或顶级文档的框架或文档名称,或您的 WB2 控件/窗口中的任何 iframe).这通常可以在 BODY 标签的 name= 属性中找到,但如果您只想将其作为 WB2 中的顶级文档加载,则您甚至不需要这样做……如果您只想将其加载为WB2 中的父顶级文档,只需执行此操作...

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

通过引用 WB2,它只会在取消 WB1 请求后向 WB2 窗口发送相同的 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.

这篇关于在 wp7 中处理 Web 浏览器链接事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆