#Windows Phone:在HTML5专案中,如何从Javascript传送字串到C#的APP端
2014-03-08 21:21
435 查看
原文:#Windows Phone:在HTML5专案中,如何从Javascript传送字串到C#的APP端
2013/11/29 02:50 |
閱讀數 : 505
|
我要推薦
|
Add Comment
| 文章分類 :
APP
HTML5
Windows Phone
|
訂閱
在開發Windows Phone APP的HTML5專案中,究竟該如何從Javascript傳給APP的C#程式碼中呢?現在就讓我來介紹一下吧!
首先先對嵌入至HTML5專案中的瀏覽器加上當觸發ScriptNotify事件時處理的函式,Javascript可藉此觸發ScriptNotify事件將字串傳給APP使用。在此範例裡,設定當Javascript傳字串過來時,就使用
註:亦可直接從xaml中增加。
接著只要在Javascript端,呼叫
這樣就可以了!底下是結果:
csjs03.png
Getting Started With Windows Phone 8 HTML5 Apps:http://blogs.msdn.com/b/matthiasshapiro/archive/2013/02/15/getting-started-with-windows-phone-8-html5-apps.aspx
var now = new Date();var index=now.getTime();document.write('');
DotBlogs Tags:
APP
HTML5
Windows Phone
#Monogame:在Windows 8 APP專案中,判斷Snap View的狀態
#Windows Phone:在HTML5專案中,如何從C#執行網頁的Javascript程式
#APP:[龜兔賽跑棋]於Windows Store上架
#Windows Phone:在HTML5专案中,如何从Javascript传送字串到C#的APP端
2013/11/29 02:50 |閱讀數 : 505
|
我要推薦
|
Add Comment
| 文章分類 :
APP
HTML5
Windows Phone
|
訂閱
在開發Windows Phone APP的HTML5專案中,究竟該如何從Javascript傳給APP的C#程式碼中呢?現在就讓我來介紹一下吧!
使Javascript能與APP的C#程式碼溝通
首先先對嵌入至HTML5專案中的瀏覽器加上當觸發ScriptNotify事件時處理的函式,Javascript可藉此觸發ScriptNotify事件將字串傳給APP使用。在此範例裡,設定當Javascript傳字串過來時,就使用MessageBox.Show將字串顯示出來。
private void Browser_Loaded(object sender, RoutedEventArgs e) { Browser.IsScriptEnabled = true; Browser.ScriptNotify += HTML_Script_Launched; // 在此加入您的 URL Browser.Navigate(new Uri(MainUri, UriKind.Relative)); } private void HTML_Script_Launched(object sender, NotifyEventArgs e) { MessageBox.Show(e.Value); }
註:亦可直接從xaml中增加。
<phone:WebBrowser x:Name="Browser" ScriptNotify="HTML_Script_Launched" />
接著只要在Javascript端,呼叫
window.external.notify函式並傳值即可。
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="/html/css/phone.css" /> <title>Windows Phone</title> <script> window.external.notify("Hello World!"); </script> </head> <body> <div> <p>我的應用程式</p> </div> <div id="page-title"> <p>頁面標題</p> </div> </body> </html>
這樣就可以了!底下是結果:
csjs03.png
參考資料
Getting Started With Windows Phone 8 HTML5 Apps:http://blogs.msdn.com/b/matthiasshapiro/archive/2013/02/15/getting-started-with-windows-phone-8-html5-apps.aspxvar now = new Date();var index=now.getTime();document.write('');
DotBlogs Tags:
APP
HTML5
Windows Phone
關連文章
#Windows Phone:安裝Windows Phone SDK 8.0流程#Monogame:在Windows 8 APP專案中,判斷Snap View的狀態
#Windows Phone:在HTML5專案中,如何從C#執行網頁的Javascript程式
#APP:[龜兔賽跑棋]於Windows Store上架
相关文章推荐
- Android TabHost TabWidget 去除黑线(底部下划线)
- 【iOS】如何设置app支持文件共享
- Android之json数据解析
- Android出现java.net.SocketException: Permission denied的问题
- Android 利用Mainfest.xml隐藏ActionBar
- Android之ContentProvider
- Prepare for Android
- 【iOS】真机测试及布署Code Sign error问题总结
- Android笔记 之 搞清楚 Application 应用
- Spine使用(With Cocos2d-x)
- Android 之 语言 国际化
- Learning the parts of object by NMF
- Android开发第一讲之目录结构和程序的执行流程
- Android实战技巧之七:按钮控制ViewPager的左右翻页
- 02-03.类和对象 Classes and Objects
- 【win8技巧】应用商店里面如何搜索应用app
- Windows Phone 8 - 建立App专属联络人资讯(ContactStore)
- 重新想象 Windows 8 Store Apps (42) - 多线程之线程池: 延迟执行, 周期执行, 在线程池中找一个线程去执行指定的方法
- IOS中Notificaiton通知的使用方法<代码演示>
- 重新想象 Windows 8 Store Apps (41) - 打印