C# 加载并调用包含javascript的html文件
我正在用VS2012编写一个包含webbrowser控件的小应用程序。我想加载一个包含javascript的html文件。webbrowser控件无法处理javascript默认值。所以我一直在读一些书 我有以下html文件:C# 加载并调用包含javascript的html文件,c#,javascript,visual-studio,webbrowser-control,C#,Javascript,Visual Studio,Webbrowser Control,我正在用VS2012编写一个包含webbrowser控件的小应用程序。我想加载一个包含javascript的html文件。webbrowser控件无法处理javascript默认值。所以我一直在读一些书 我有以下html文件: <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var centerlatlng = new google.maps.LatLng(45.046006, -105.245867);
var myOptions = {
zoom: 13,
center: centerlatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
</script>
</head>
<body style="margin:0px; padding:0px;">
<div id="map_canvas" style="width: 100%; height: 100%;"></div>
</body>
</html>
因此,我的问题是:
看起来以下代码适合我:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
maps_webbrowser.DocumentText = File.ReadAllText(@"GPSmap.html");
}
private void maps_webbrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Debug.WriteLine(maps_webbrowser.DocumentText.ToString());
maps_webbrowser.Document.InvokeScript("initialize");
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
maps_webbrowser.DocumentText = File.ReadAllText(@"GPSmap.html");
}
private void maps_webbrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Debug.WriteLine(maps_webbrowser.DocumentText.ToString());
maps_webbrowser.Document.InvokeScript("initialize");
}
}