<pre class="brush:c#;toolbar:false">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;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;
namespace WindowsFormsApplication1
{
//[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
//[ComVisible(true)]//COM+组件可见
public partial class FrmWebCef : Form
{
public static string url="";
public FrmWebCef(string _url)
{
InitializeComponent();
try
{
url = ConfigurationManager.AppSettings["url"].ToString();
}
catch { }
}
private void Form1_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
settings.Locale = "zh-CN";
settings.CachePath = Directory.GetCurrentDirectory() + @"\Cache";
//settings.AcceptLanguageList="zh-CN";
settings.CefCommandLineArgs.Add("disable-application-cache", "1");
settings.CefCommandLineArgs.Add("disable-session-storage", "1");
if (!Cef.IsInitialized) Cef.Initialize(settings);
// Cef.Initialize(settings);
CefSharp.WinForms.ChromiumWebBrowser wb = new CefSharp.WinForms.ChromiumWebBrowser(url);
wb.Dock = DockStyle.Fill;
// CefSharp.CefSettings settings = new CefSharp.CefSettings();
//// settings. = "zh-CN";
// settings.Locale = "zh-CN";
//// <html><head><meta http-equiv="content-type" content="text/html;charset=GBK">
////</head><body><input type="text" value="send" id="input">
////<input type="button" value="send" id="button" onclick="Cl();">
////<script type="text/javascript">
//// document.getElementById('button').onclick = function () {
//// debugger;
//// alert('测试1');
//// // window.extend.Close('测试');
//// window.parent.postMessage('this is test!index1', '*');
//// };
//// function Cl() {
//// debugger;
//// alert('测试');
//// parent.postMessage('this is test!index', '*');
//// }
////</script></body></html>
// <html><head><meta http-equiv="x-ua-compatible" content="IE=10,chrome=1">
//</head><body style="margin:0;padding:0;overflow:hidden" scroll="no"><iframe width="100%" height="100%" marginwidth="0" marginheight="0" border="0" src="http://zhenggc.cc/indext.html"></iframe>
//<script type="text/javascript"> var mess=''; function receiveMessage(e) { alert('csharp _html:' +e.data);mess=e.data; csh.CloseMe(e.data);} window.addEventListener("message", receiveMessage, false);function go(){ window.external.Close(); } </script> </body></html>
// Cef.Initialize(settings);
// settings.l
// CefSharpSettings.LegacyJavascriptBindingEnabled = true;
string html = "<html><head><meta http-equiv=\"x-ua-compatible\" content=\"IE=10,chrome=1\"></head><body style=\"margin:0;padding:0;overflow:hidden\" scroll=\"no\"><iframe width=\"100%\" height=\"100%\" marginwidth=\"0\" marginheight=\"0\" border=\"0\" src=\"" + url + "\"></iframe>" +
"<script type=\"text/javascript\"> var mess=''; function receiveMessage(e) { alert('csharp_html:' +e.data);mess=e.data; csh.CloseMe(e.data);} window.addEventListener(\"message\", receiveMessage, false); </script> </body></html>";
wb.LoadHtml(html, "http://zhenggc.cn/indext.html");
// wb.JsDialogHandler
wb.RegisterJsObject("csh", this, false);
// wb.DownloadHandler = new CefSharpDownloadHandler();
this.Controls.Add(wb);
}
public void CloseMe(string mess)
{
MessageBox.Show("cSHarp" + mess);
if (mess.Equals("kclose"))
{
this.Close();
}
}
}
}</pre><p><br/></p>