本文介绍了通过google doc viewer在webKitBrowser中显示word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个带有webKitBrowser的表单。用户应该在互联网上冲浪,当他点击* .doc链接时,必须显示word文档。当用户点击.doc链接时,我在哪里可以告诉浏览器该做什么? 更新: 我已经完成了这个(使用System.Web.dll): namespace testGoogleDoc { public partial class Form1:Form { 静态 bool IsDocumentToRedirect( string url) { return url.ToLower()。EndsWith( 。doc)|| url.ToLower()。EndsWith( 。docx); } // IsDocumentToRedirect public Form1() { InitializeComponent(); browser.Navigate( http://www.google.com); // BrowserHomePage } private void browser_Navigating( object sender,WebBrowserNavigatingEventArgs e) { string urlString = e.Url.ToString(); if (urlString.ToLower()。StartsWith( https://www.google.com/url?q=)|| urlString.ToLower()。StartsWith( http://www.google.com/url?q=)) { Uri uri = new Uri(urlString); Uri doc = new Uri(HttpUtility.ParseQueryString(uri.Query).Get( q)); urlString = doc.OriginalString.ToLower(); } if (IsDocumentToRedirect(urlString)&&!urlString.ToLower()。StartsWith( https://docs.google.com/viewer)) { e.Cancel = 真; browser.Navigate( https://docs.google.com/viewer?url= + urlString); } } } } 有没有一种最好的方法来提取其他复杂URL的查询部分中的正确URL?解决方案 i have a form with a webKitBrowser. The user should surf on internet, and when he click a *.doc link, the word document must be shown. where can i tell the browser what to do when the user click on a .doc link?update:i''ve done this (using System.Web.dll):namespace testGoogleDoc{ public partial class Form1 : Form { static bool IsDocumentToRedirect(string url) { return url.ToLower().EndsWith(".doc") || url.ToLower().EndsWith(".docx"); } //IsDocumentToRedirect public Form1() { InitializeComponent(); browser.Navigate("http://www.google.com"); //BrowserHomePage } private void browser_Navigating(object sender, WebBrowserNavigatingEventArgs e) { string urlString = e.Url.ToString(); if (urlString.ToLower().StartsWith("https://www.google.com/url?q=") || urlString.ToLower().StartsWith("http://www.google.com/url?q=")) { Uri uri = new Uri(urlString); Uri doc = new Uri(HttpUtility.ParseQueryString(uri.Query).Get("q")); urlString = doc.OriginalString.ToLower(); } if (IsDocumentToRedirect(urlString) && !urlString.ToLower().StartsWith("https://docs.google.com/viewer")) { e.Cancel = true; browser.Navigate("https://docs.google.com/viewer?url=" +urlString); } } } }is there a best way to extract the right URL in the query part of the other complexed URL? 解决方案 这篇关于通过google doc viewer在webKitBrowser中显示word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 20:17