C#Webkit不会显示Html

时间:2016-09-09 06:58:59

标签: c# html webkit

我已将 WebkitBrow.Net 中的 WebkitBrowser 包含到我的C#项目中,它可以正常工作,除非我想加载一个Html 字符串即可。这是我要显示的Html:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
    <meta name="viewport" content="width=device-width, initial-scale=2">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>mentor+</title>
    <link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<link rel="stylesheet" type="text/css" href="./wicket/resource/org.apache.wicket.Application/css/style-ver-1463736306000.css" />
<link rel="stylesheet" type="text/css" href="./wicket/resource/org.apache.wicket.Application/css/landingpage-ver-1463664722000.css" />
<link rel="stylesheet" type="text/css" href="./wicket/resource/org.apache.wicket.Application/font-awesome/css/font-awesome.min-ver-1448702160000.css" />
<link rel="stylesheet" type="text/css" href="./wicket/resource/org.apache.wicket.Application/vis/vis.min-ver-1460038992000.css" />
<link rel="stylesheet" type="text/css" href="./wicket/resource/de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference/webjars/bootstrap/3.3.6/css/bootstrap-ver-1455709722000.css" />
</head>
    <body>
    <div>

    </div>

<div>
<div class="container-fluid">

    <div class="bs-example">

        <div class="jumbotron">

            <div id="mynetwork" ></div>
        </div>
    </div>
</div>
</div>
    <footerbucket><script type="text/javascript" src="./wicket/resource/org.apache.wicket.resource.JQueryResourceReference/jquery/jquery-1.12.0-ver-1457005336000.js"></script>
<script type="text/javascript" src="./wicket/resource/org.apache.wicket.ajax.AbstractDefaultAjaxBehavior/res/js/wicket-event-jquery-ver-1457005336000.js"></script>
<script type="text/javascript" src="./wicket/resource/org.apache.wicket.Application/js/topButton-ver-1462984064000.js"></script>
<script type="text/javascript" src="./wicket/resource/org.apache.wicket.Application/js/jquery-1-12-1-min-ver-1462366394000.js"></script>
<script type="text/javascript" src="./wicket/resource/org.apache.wicket.Application/vis/vis.min-ver-1463655366000.js"></script>
<script type="text/javascript" src="./wicket/resource/org.apache.wicket.Application/js/networkgraph-ver-1463047612000.js"></script>
<script type="text/javascript" src="./wicket/resource/de.agilecoders.wicket.core.markup.html.references.JQueryMigrateJavaScriptReference/js/jquery-migrate-1.3.0-ver-1457345416000.js">    </script>
<script type="text/javascript" id="bootstrap-js" src="./wicket/resource/de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference/webjars/bootstrap/3.3.6/js/bootstrap-ver-1455709722000.js"></script>
<script type="text/javascript" >
/*<![CDATA[*/
Wicket.Event.add(window, "load", function(event) { 
createNetwork(new vis.DataSet([{"id":0,"label":"Amalie","color":"#FA5858"},{"id":1,"label":"Daniel","color":"#2E64FE","shape":"box"},{"id":2,"label":"Carola","color":"#01DF01","shape":"ellipse"},{"id":3,"label":"Annette","color":"#58FAF4","shape":"ellipse"},{"id":4,"label":"Marius","color":"#58FAF4","shape":"box"}]),new vis.DataSet([{"id":0,"from":0,"to":1,"length":80,"width":6,"color":"#2E64FE"},{"id":1,"from":0,"to":2,"length":40,"width":6,"color":"#01DF01"},{"id":2,"from":0,"to":3,"length":40,"width":6,"color":"#58FAF4"},{"id":3,"from":0,"to":4,"length":40,"width":6,"color":"#58FAF4"}]));
;});
/*]]>*/
</script>
</footerbucket>
</html>
</body>

我用Cefsharp和serveraddress一起使用它,它起作用了:

ChromiumWebBrowser cef = new ChromiumWebBrowser();
cef.LoadHtml(responseFromServer, server + "home");

如您所见,一个参数是serveraddress。

如果我将Html字符串导出到文件中并尝试使用任何浏览器加载它,它也无法正常工作,所以我认为需要提供服务器地址,但我找不到任何拟合方法。请你能帮帮我吗?

编辑:

现在我编辑了服务器中的代码,它将使用POST参数,它适用于每个浏览器。除了WebKit!

现在,网址如下所示:

http://mentorplus.de/networkgenerator/getNetworkgraph?network=[{%22focusPerson%22:%22Amalie%22,%22memberList%22:[{%22role%22:%22MENTOR%22,%22name%22:%22Daniel%22,%22gender%22:%22MALE%22,%22relationship%22:%22FRIENDS%22,%22emotionalRelationship%22:%22NORMAL%22,%22distance%22:%22TWOHOUR%22},{%22role%22:%22MENTOR%22,%22name%22:%22Carola%22,%22gender%22:%22FEMALE%22,%22relationship%22:%22FAMILY%22,%22emotionalRelationship%22:%22NORMAL%22,%22distance%22:%22ONEHOUR%22},{%22role%22:%22NETWORKMEMBER%22,%22name%22:%22Annette%22,%22gender%22:%22FEMALE%22,%22relationship%22:%22OTHER%22,%22emotionalRelationship%22:%22NORMAL%22,%22distance%22:%22ONEHOUR%22},{%22role%22:%22NETWORKMEMBER%22,%22name%22:%22Marius%22,%22gender%22:%22MALE%22,%22relationship%22:%22OTHER%22,%22emotionalRelationship%22:%22NORMAL%22,%22distance%22:%22ONEHOUR%22}]}]&authenticated=tellur

那么究竟什么是WebKit的问题?也许脚本?

编辑2:

有趣的是,使用标准Wpf浏览器可以正常工作。所以我将这个帖子标记为已回答,但我仍然对解决方案感兴趣

非常感谢!

1 个答案:

答案 0 :(得分:1)

不幸的是,使用WebKitBrowser中的WebKit.NET并没有直接的方法。但是,应该可以通过跳过几个循环来加载HTML字符串。

在内部,WebKitBrowserCore课程使用_webView.mainFrame().loadHTMLString(Text, null)属性的set方法调用DocumentText。这证实了内部至少可以进行某种HTML加载。但是,此方法位于本机WebKit WebView中,因此您需要修改项目才能访问它。

我创建项目的分支并执行以下更改。

  1. WebKitBrowserCore调用LoadHTMLString添加一个新方法,其中包含两个HTML字符串和服务器地址参数。
  2. 使用参数调用_webView.mainFrame().loadHTMLString(html, server);方法。
  3. LoadHTMLString方法与其他类似方法展示给WebKitBrowser类,例如Navigate方法(它只调用核心的Navigate方法。
  4. 我现在无法对此进行测试,因此我不能完全确定WebView的内部loadHTMLString方法是否按预期工作。

    修改:您似乎也可以使用WebKitBrowser中的GetWebView方法直接调用mainFrame().loadHTMLString()方法(语法可能不正确,但您可以“我想出来了):

    (IWebView)webKitBrowser.GetWebView()).mainFrame().loadHTMLString(html, server);
    

    编辑2:我刚刚意识到WebKit是一个开源项目,并且很容易验证loadHTMLString是否符合我的想法。这是WebFrame.h头文件的摘录:

    /*!
        @method loadHTMLString:baseURL:
        @param string The string to use for the main page of the document.
        @param URL The base URL to apply to relative URLs within the document.
        - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)URL;
    */
    
    HRESULT loadHTMLString([in] BSTR string, [in] BSTR baseURL);
    

    这是你需要调用的确切方法,也是CEFSharp在内部调用的方法。