Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加载并调用包含javascript的html文件_C#_Javascript_Visual Studio_Webbrowser Control - Fatal编程技术网

C# 加载并调用包含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

我正在用VS2012编写一个包含webbrowser控件的小应用程序。我想加载一个包含javascript的html文件。webbrowser控件无法处理javascript默认值。所以我一直在读一些书

我有以下html文件:

<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>
因此,我的问题是:

  • 如何将包含javascript的*.html文件加载到webbrowser中

  • 如何从html文件调用javascript函数

  • 如何正确导航到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");
        }
    }