我想让webBrowser打开HTML字符串。到目前为止,这是我在webBrowser中打开HTML字符串所得到的:
public void show()
{
routelistBrowser.ScriptErrorsSuppressed = true;
reisOpties = fakeLijst(gekozenTijd);
RouteListPanel rlp = new RouteListPanel();
rlp.Session = new Dictionary<string, object>();
rlp.Session["reisOpties"] = reisOpties;
rlp.Initialize();
Console.WriteLine(rlp.TransformText());
DisplayHtml(rlp.TransformText());
}
private void DisplayHtml(string html)
{
routelistBrowser.Navigate("");
HtmlDocument doc = routelistBrowser.Document.OpenNew(true);
doc.Write(html);
routelistBrowser.Refresh();
Console.WriteLine(html);
}
我的问题是我的webBrowser无法加载此HTML字符串。我不确定自己在做什么错。我已经在用户控件中添加了webBrowser,并在主窗体中添加了该用户控件。 webBrowser将显示,但不会加载HTML字符串。 输出控制台(HTML字符串):
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<title></title>
<style type="text/css">
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id ="container" class="container">
<ul style="list-style-type:none;">
<li>
<div>
<h1>17:54 --> 18:13</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:00 --> 18:19</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:06 --> 18:25</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:12 --> 18:31</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:18 --> 18:37</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:24 --> 18:43</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
<ul style="list-style-type:none;">
<li>
<div>
<h1>18:30 --> 18:49</h1><h3>Totale tijd: 0:19
Aantaloverstappen: 0x Perron: 1a</h3>
<h3>NS - Intercity</h3>
</div>
</li>
</ul>
</div>
</body>
</html>