using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CefSharp.WinForms;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace cefsharpform
{
public partial class Form1 : Form
{
CefSharp.WinForms.ChromiumWebBrowser browser;
public Form1()
{
InitializeComponent();
browser = new ChromiumWebBrowser("http://www.google.com");
browser.Name = "Simple Page";
browser.Dock = DockStyle.Fill;
//當load結束的時候,所要執行的事件方法
browser.FrameLoadEnd += new EventHandler(browser_FrameLoadEnd);
this.Controls.Add(browser);
}
void browser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
if (e.HttpStatusCode == 200)
{
//在browser中執行一段Javascript
browser.ExecuteScriptAsync("alert('Test!');");
//呼叫一個javascript function, 並取得其回傳值
var task = browser.EvaluateScriptAsync(@"
(function () {
return 'hello!';
})();
");
var complete = task.ContinueWith(t =>
{
if (!t.IsFaulted)
{
var response = t.Result;
object result = response.Success ? (response.Result ?? "null") : response.Message;
MessageBox.Show(task.Result.Result.ToString());
}
}, TaskScheduler.Default);
complete.Wait();
}
else
{
this.Close();
}
}
}
}
2015-09-20
cefSharp example by using c# (Chromium-based browser component)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment