您的位置:首页 > Web前端 > JavaScript

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: