关于webbrowser

 
1,加载本地html文件
using System.IO; using Microsoft.Xna.Framework; 
StreamReader reader = new StreamReader( TitleContainer.OpenStream( "html/wp7wiki.html"));
Browser.NavigateToString(reader.ReadToEnd());
2,默认不开script,用isscriptenabled开启

XAML

< phone : WebBrowser x : Name ="Browser" IsScriptEnabled ="True" />

C#

Browser.IsScriptEnabled = true;
 
3, 在你的app和script 之间传递信息
若要把数据从app传到page,可以简单的调用.InvokeScript(). 他有两个重载函数,无参和有参:
public Object InvokeScript( string scriptName )
public Object InvokeScript( string scriptName, params Object[] args ) s
criptName是脚本的函数名,args是函数的参数列表,如: string returnValue = ( string)Browser.InvokeScript( "getText", "http://jeffblankenburg.com", "rocks", "awesomely"); 
 
若相反,即从script传数据到app, 首先script要触发一个scriptnotify事件:window.external.Notify( http://jeffblankenburg.com);(以传url为例)然后在app中设置一个notify event handle:.ScriptNotify.
void Browser_ScriptNotify( object sender, NotifyEventArgs e) { Browser.Navigate( new Uri(e.Value, UriKind.Absolute)); } 
//NotifyEventArgs.Value是script传递的数据
 
4,可以使用进度条来表示正在加载页面

XAML

< ProgressBar Foreground ="Orange" x : Name ="ProgBar" Visibility ="Collapsed" IsIndeterminate ="True" Height ="4" HorizontalAlignment ="Left" Margin ="10,66,0,0" VerticalAlignment ="Top" Width ="460" />

C#

void Browser_Navigating( object sender, NavigatingEventArgs e) { ProgBar.Visibility = Visibility.Visible; } void Browser_Navigated( object sender, System.Windows.Navigation. NavigationEventArgs e) { ProgBar.Visibility = Visibility.Collapsed; }
 
 
http://www.jeffblankenburg.com/2010/10/18/31-days-of-windows-phone-day-18-webbrowser-control/

你可能感兴趣的:(windows,phone,7,webbrowser,object,browser,string,脚本,html)