C# Webkit won't display Html
本文关键字:display Html Webkit won | 更新日期: 2023-09-27 18:06:30
我已经从WebKit中包含了WebkitBrowser。Net进入我的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的服务器地址,它工作:
ChromiumWebBrowser cef = new ChromiumWebBrowser();
cef.LoadHtml(responseFromServer, server + "home");
如您所见,其中一个参数是服务器地址。
如果我导出的html字符串到一个文件,并尝试加载它与任何浏览器,它也不工作,所以我认为服务器地址需要提供,但我找不到任何合适的方法。你能帮帮我吗?
<标题>编辑:现在我编辑了来自服务器的代码,它将与POST参数一起工作,并且它可以在每个浏览器中工作。除了WebKit !
URL现在看起来像这样:
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浏览器工作。所以我把这个线程标记为回答,但我仍然对解决方案感兴趣
非常感谢!
标题>标题>不幸的是,使用WebKit.NET的WebKitBrowser没有直接的方法来做到这一点。但是,应该可以通过跳过几个循环来加载HTML字符串。
在内部,WebKitBrowserCore类在DocumentText
属性的set方法中调用_webView.mainFrame().loadHTMLString(Text, null)
。这证实了至少可以在内部加载某种HTML。然而,这个方法是在原生WebKit的WebView中,所以你需要修改项目来访问它。
我会创建一个项目的分支,并做以下更改。
- 为
WebKitBrowserCore
添加LoadHTMLString方法,包含HTML字符串和服务器地址两个参数。 - 使用参数调用
_webView.mainFrame().loadHTMLString(html, server);
方法 - 将
LoadHTMLString
方法暴露给WebKitBrowser类,就像其他方法一样,例如导航方法(它只是调用核心的导航方法。
我不能测试这个现在,所以我不完全确定如果内部loadHTMLString方法的WebView工作的预期。
编辑:看起来你也可以使用GetWebView
方法在WebKitBrowser,调用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内部调用的方法。