1.Invoke和InvokeSelf public partial class CreateJSDemo : UserControl { public CreateJSDemo() { InitializeComponent(); string jsText = @"function callJs(msg){alert(msg);}"; //function可以是在此处创建,也可以是已经在页面存在的function HtmlElement element = HtmlPage.Document.CreateElement("Script"); element.SetAttribute("type", "text/javascript"); element.SetProperty("text", jsText); HtmlPage.Document.Body.AppendChild(element); } private void btn_Invoke_Click(object sender, RoutedEventArgs e) { HtmlPage.Window.Invoke("callJs", "Haha"); } private void btn_InvokeSefy_Click(object sender, RoutedEventArgs e) { ScriptObject script = HtmlPage.Window.GetProperty("callJs") as ScriptObject; script.InvokeSelf("God bless you!"); } } 2.CreateInstance public partial class CallJsByCreateInstance : UserControl { public CallJsByCreateInstance() { InitializeComponent(); string jsText = @" jsObject = funciton callJs(msg) { this.Msg=msg; } jsObject.property.show=function { alert(this.Msg); } "; HtmlElement element = HtmlPage.Document.CreateElement("Script"); element.SetAttribute("type", "text/javascript"); element.SetProperty("text", jsText); HtmlPage.Document.Body.AppendChild(element); } private void btn_CreateInstance_Click(object sender, RoutedEventArgs e) { ScriptObject script = HtmlPage.Window.CreateInstance("jsObject", "Haha"); script.Invoke("show"); } }