导航网页的槽的目的,使用嵌入式Web浏览器 [英] Navigating trough objects of a web page, using an embedded web browser

查看:151
本文介绍了导航网页的槽的目的,使用嵌入式Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序使用 web浏览器控件来显示嵌入网页。该文件是(成功),使用加载:

I have a Windows Forms application that uses a WebBrowser control to display an embedded web page. The file is (successfully) loaded using:

webHelp.DocumentStream=
          Assembly.GetExecutingAssembly()
          .GetManifestResourceStream("MyAssembly.help.html");

为了这个工作(即文件/显示加载)我设置了 webHelp.AllowNavigation = FALSE; 。我不完全理解为什么,但如果它设置为true,则不会显示该页面。

In order for this to work (i.e. the file to be loaded/displayed) I set the webHelp.AllowNavigation = false;. I don't fully understand why, but if it's set to true, the page is not displayed.

在我的HTML文件(参见下文),我希望能够浏览低谷的不同部分。但是,当我点击一个链接时,浏览器控件不进入目标元素。该网页作品在独立的Internet Explorer 10细,所以它必须有一些做的控制,更具体地说是 AllowNavigation 属性。 MSDN没有多大帮助。

In my HTML document (see bellow) I want to be able to navigate trough different sections. But when I click on a link, the browser control does not go to the targeted element. The web page works fine in the stand-alone Internet Explorer 10, so it must have something to do with the control, more specifically the AllowNavigation property. MSDN didn't help much.

我怎样才能做到这一点的导航行为?有没有加载HTML文件,而不 AllowNavigation 属性设置为false的另一种方式?

How can I achieve this navigation behavior? Is there another way of loading the HTML file without setting the AllowNavigation property to false?

这是我简单的HTML文件:

This is my simple HTML file:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Using this tool</title>
</head>
<body>
    <h3>Description</h3>
    <div><p id="contents">Contents</p></div>
    <div>
        <p id="general">Using the file converter</p>
        <p>*converter description*</p>
        <a href="#contents" class="goToTop">Go To Top!</a>
    </div>
    <div class="divBlock" >
        <p id="selectOption">Selecting a conversion action</p>
        <p>*action selection*</p>
        <a href="#contents" class="goToTop">Go To Top!</a>
    </div>
</body>
</html>



编辑:经过额外的测试,我发现了问题的根源。设置为网址属性的值,运行应用程序,事后清算这个值后,问题出现了。嵌入式页面没有加载任何更多的,除非 AllowNavigation 属性设置为。有两个解决方案,在我的答案描述如下

After additional tests I found the root of the problem. The problem appeared after setting a value for the URL property, running the application and afterwards clearing this value. The embedded page is not loaded any more, unless the AllowNavigation property is set to false. There are two solutions, described in my answer bellow.

推荐答案

编辑:找出原因后问题(见编辑的问题)我现在可以提出三种解决方案:

After finding the cause of the problem (see the edit to the question) I can now propose three solutions:

1。 web浏览器控制替换:结果
只需删除现有的 web浏览器控件并添加新的一个。该解决方案不要求 AllowNavigation 财产的任何修改。不要修改网址属性。

1. WebBrowser control replacement:
Simply delete the existing WebBrowser control and add a new one. This solution does not require any modification of the AllowNavigation property. DO NOT modify the URL property.

2。当删除和添加一个新的 web浏览器控制不是一个选项:结果
由于 AllowNavigation 财产影响负荷和网页显示,没有理由为它留给之后。设置早在所示事件属性解决导航问题,而不需要其他的改变(例如,在HTML文件或注册表):

2. When deleting and adding a new WebBrowser control is not an option:
Since the AllowNavigation property was influencing the loading and displaying of the web page, there was no reason for it to be left to false afterwards. Setting back the property in the Shown event solved the navigation problem, without requiring other alterations (e.g. in the HTML file or the Registry):

private void helpForm_Shown(object sender, EventArgs e)
{
    webHelp.AllowNavigation = true;
}



3。正在重置的文件 结果
它接缝的文件属性获取(自动)如果初始化网址属性是设置和重置一次。添加 webHelp.Document.OpenNew(真); 然后再加载资源流解决,而不需要对这个问题重新添加 web浏览器键,无需修改 AllowNavigation 属性。

3. Reseting the Document
It seams that the Document property gets (automatically) initialized if URL property is at one time set and reset. Adding webHelp.Document.OpenNew(true); before loading the resource stream solves the problem without the need for re-adding the WebBrowser and without modifying the AllowNavigation property.

这篇关于导航网页的槽的目的,使用嵌入式Web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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