Silverlight 4 WebBrowser的使用及调用 WebBrowser 中的 javascript 方法
2012-10-17 15:00
447 查看
下面是MSDN的使用说明:
The following example shows how to handle the ScriptNotify event. In this example, the InvokeScript is called, which in turn calls the LoadSearch function in the following HTML.
The HTML file must be hosted in the same domain as the Silverlight application. The Javascript within the HTML page calls window.external.notify,
which raises the ScriptNotify event in the Silverlight application
必须在同一个域下才可用哦!example:
The following example shows how to handle the ScriptNotify event. In this example, the InvokeScript is called, which in turn calls the LoadSearch function in the following HTML.The HTML file must be hosted in the same domain as the Silverlight application. The Javascript within the HTML page calls window.external.notify, which raises the ScriptNotify event in the Silverlight application.
View Codewith code-behind;
view plaincopy to clipboardprint?View Codewith some code behind it ( note – I feel I should be able to set the WebBrowser.Source property from XAML but it’s not working for me at the time of writing );
view plaincopy to clipboardprint?
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SilverlightApplication18 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); this.Loaded += (s, e) => { myBrowser.Source = new Uri("http://www.microsoft.com", UriKind.Absolute); }; } private void OnRedraw(object sender, RoutedEventArgs e) { myBrush.Redraw(); } } }
then that gives me a UI where I’m painting the rectangle on the right hand side with that HtmlBrush pointing to theWebBrowser control on the left hand side;
Note – this isn’t a VisualBrush and so it doesn’t do “live updates”. You’ll notice the Redraw button and the call toHtmlBrush.Redraw and that’s the mechanism for keeping things in sync so it’s more like a snapshot than anything else but pretty interesting regardless.
相关文章推荐
- WPF WebBrowser使用JavaScript调用外部方法决解方法简介
- 使用ajax,javascript中调用后台的方法
- 在页面上使用javascript调用aspx.cs后台方法
- 获取iframe中的内容、查找获取指定元素(关于用c++调用WEBBROWSER控件,使用相关接口操作web页面元素的一些方法)
- 使用 AjaxManager 生成调用服务器端方法的 javascript 函数
- 第2章 两种调用JS的方法——在HTML中使用JavaScript
- 如何使用Javascript调用.NET 2.0用户控件中的方法和属性
- WebView原生方法---使用javascript调用android代码
- [Silverlight探秘]利用Javascript调用silverlight的方法
- Silverlight和浏览器交互(2)----Silverlight中使用托管代码调用JavaScript
- 使用Javascript调用Silverlight
- javascript数组使用调用方法汇总
- SilverLight学习笔记--Silverligh之在SL中调用Javascript (四种调用方法+简单与复杂参数的传递)
- AJAXPRC实现了使用Javascript调用服务端方法
- 怎样在前端Javascript中调用C#方法(3)使用特性Attribute
- 第三部分 02 在ASP.NET AJAX应用程序中使用JavaScript异步调用Page的方法
- 使用WebView中的JavaScript调用android的方法
- C# 窗体 webbrowser 窗体调用javascript方法 实例
- Asp.net中使用javaScript实现前后台方法的相互调用
- SilverLight浏览器交互之:Html页面通过Javascript调用SilverLight程序内方法(附源码)