2
我有一個Silverlight應用程序,它可以與我的攝像頭進行通信以拍攝照片。在Silverlight中調用javascript
的Silverlight代碼
protected void photoButton_Click(object sender, RoutedEventArgs e)
{
this.src.CaptureImageCompleted += (s, a) =>
{
this.lastSnapshot = a.Result;
this.snapshot.Visibility = Visibility.Visible;
this.snapshot.Source = this.lastSnapshot;
HtmlPage.Window.Invoke("SalvaFoto");
this.src.Stop();
};
src.CaptureImageAsync();
}
ASPX當我把我的Silverlight應用程序
var htmlEmbedSilverlight = "<div id='silverlightControlHost'> "
+ "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='550px' height='250px'> "
+ "<param name='source' value='../../ClientBin/FotoEmprestimoChave.xap'/> "
+ "<param name='onError' value='onSilverlightError' /> "
+ "<param name='background' value='white' /> "
+ "<param name='minRuntimeVersion' value='4.0.60310.0' /> "
+ "<param name='autoUpgrade' value='true' /> "
+ "<param name='InitParams' value='chave_id=" + data + "' /> "
+ "<a href='http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0' style='text-decoration:none'> "
+ "<img src='http://go.microsoft.com/fwlink/?LinkId=161376' alt='Get Microsoft Silverlight' style='border-style:none'/> "
+ "</a> "
+ "</object><iframe id='_sl_historyFrame' style='visibility:hidden;height:0px;width:0px;border:0px'></iframe></div>";
$("#tiraFotoSilverlight").html(htmlEmbedSilverlight);
問題
當我嘗試執行當前0123的頁面HtmlPage.Windows.Invoke("javascript_method");
不起作用。
我做錯了什麼?
我也試試下面的代碼,但沒有成功
protected void photoButton_Click(object sender, RoutedEventArgs e)
{
this.src.CaptureImageCompleted += (s, a) =>
{
this.lastSnapshot = a.Result;
this.snapshot.Visibility = Visibility.Visible;
this.snapshot.Source = this.lastSnapshot;
HtmlElement Script = HtmlPage.Document.CreateElement("script");
Script.SetAttribute("type", "text/javascript");
Script.SetProperty("text", "$(document).ready(function() { alert('hi'); });");
this.src.Stop();
};
src.CaptureImageAsync();
}
它不工作,發生例外 –