webKitBrowser * .doc链接点击 [英] webKitBrowser *.doc link click

查看:100
本文介绍了webKitBrowser * .doc链接点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在标签中显示浏览器的点击链接。每次用户点击链接时,链接都会显示在标签中,当我点击* .doc时,标签的值不会改变,也不会发生任何变化!我知道使用默认浏览器会很容易,我改为网络工具包,因为它很慢,当用户上网时它会冻结整个应用程序。有人可以帮我这个吗?



I try to show the clicked link of the browser in a label. Every time the user click on a link, the link is shown in the label, exept when i click on a *.doc, the value of the label dont change and nothing happen! I know It will be much easy with the default browser, i changed to web kit because it was ver laggy and it freeze the whole application when the user is surfing. can someone help me with this please??

private void webKitBrowser1_Navigated(object sender, WebKitBrowserNavigatedEventArgs e)
    {
        label1.Text = Convert.ToString(webKitBrowser1.Url);
    }





似乎当我点击.doc链接时,如果我没有点击在任何地方..比如在webKitBrowser中禁用.doc点击并且我们应该启用它



it seems that when i click on a .doc link nothin happen, like if i didn''t click anywhere.. like if the .doc click is disabled in webKitBrowser and we should enable it

推荐答案

这是因为你并没有真正导航到* .DOC。顺便说一句,你需要开始使用调试器。



-SA
This is because you don''t really navigate to *.DOC. You need to start using the debugger, by the way.

—SA


好的,我花了一些时间为你找到完整的解决方案。从第一次尝试开始就很容易和工作!



你只是忽略了我的一些话。我是否已告诉您使用其他活动并取消重定向到href =https://docs.google.com/viewer?url = ...?另外,请注意:此网址为HTTPS。



现在,我将展示如何。这是一个完整的解决方案,全部使用代码而不使用设计器,将其全部显示在一个文件中:

OK, I took some time and got the complete solution for you. It was easy and worked from the first attempt!

You just ignored some of my words. Did I tell you to use another event and cancel redirection to "href="https://docs.google.com/viewer?url=..."? Also, pay attention: this URL is HTTPS.

Now, I''ll show how. This is a complete solution, all in code, without the use of the designer, to show it all in one file:
using System.Windows.Forms;

//...

public class MyForm : Form {

    const string viewer = "https://docs.google.com/viewer";
    const string viewerUrl = viewer + "?url={0}";
    const string docSample = "https://docs.google.com/viewer?url=http://www.gotw.ca/publications/C%2B%2BCLIRationale.pdf";

    WebBrowser browser = new WebBrowser(); // you probably do it in designer, but I want to show all in 1 file

    static bool IsDocumentToRedirect(string url) {
        return url.ToLower().EndsWith(".pdf");
        // you can also use .doc and .docx, I did PDF for my testing
    } //IsDocumentToRedirect

    public MyForm() {
        browser.Dock = DockStyle.Fill; // would be done in designer
        browser.Parent = this; // would be done in designer
        // commented out, to show that the designer is not used, 3 lines of code replace it:
        // InitializeComponent()
        browser.Navigating += (sender, eventArgs) => {
            string urlString = eventArgs.ToString();
            if (IsDocumentToRedirect(urlString) && !urlString.ToLower().StartsWith(viewer)) {
                eventArgs.Cancel = true;
                browser.Navigate(string.Format("{0},{1}", eventArgs.Url));
            } //if
        }; //browser.Navigating
    } //MyForm

    protected override void OnShown(EventArgs e) {
        // this is done just to simulate the click on anchor and test
        // redirection:
        this.browser.Navigate(docSample);
    } //OnShown

} //class MyForm





请注意,我使用 System.Windows.Forms.WebBrowser 。我简化了代码,在显示的表单上只显示了一个测试。

我希望你有这个想法。仅在导航开始并且可以取消时处理事件的关键。



我希望你有了这个想法并且可以看到代码中缺少的内容(你以前的问题)。



祝你好运,

-SA



Please note that I uses System.Windows.Forms.WebBrowser. I simplified down the code, to show only one test, on form shown.
I hope you got the idea. The key it to handle the event when the navigation is only started and can be cancelled.

I hope you got the idea and can see what was missing from your code (your previous question).

Good luck,

—SA


这篇关于webKitBrowser * .doc链接点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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