HTML5 on Windows Phone (2) use HTML5 on Windows Phone mango and interact with HTML5

Source: Internet
Author: User

Usually use localProgramToHtm5Will not use your own browser to carryHTML5Because the cost and efficiency are not guaranteed.

InMicrosoft. Phone. ControlsIn the Assembly, Microsoft providesWebbrowserControl, you can setWebbrowserControlUriAttribute or usageNanvigateMethod to navigateUriTo displayHTML5Page.

Example:

grid x : name =" layoutroot " background =" Transparent ">

phone : webbrowser x : name =" Browser " isscriptenabled =" true "/>

</Grid>

IsscriptenabledProperty indicates whether the current browser control supports scripts.

InAssetsThere are three items in the folder FirstJqueryOfJSFramework,Sandcu.htmlIsHTML5Page, using15ItemsCanvasTo drawSceneIn15As a simple puzzle.

InMainpageBackgroundCodeMedium

PublicMainpage ()

{

Initializecomponent ();

Using(IsolatedstoragefileStore =Isolatedstoragefile. Getuserstoreforapplication ())

{

If(! Store. fileexists ("Sandcu.html"))

{

Createfile (store,"Sandcu.html",Application. Getresourcestream (New Uri("Assets/sandcu.html",Urikind. Relative). Stream );

}

If(! Store. fileexists ("Jquery. js"))

{

Createfile (store,"Jquery. js",Application. Getresourcestream (New Uri("Assets/jquery. js",Urikind. Relative). Stream );

}

If(! Store. fileexists ("Scene.jpg"))

{

Createfile (store,"Scene.jpg",Application. Getresourcestream (New Uri("Assets/scene.jpg",Urikind. Relative). Stream );

}

}

Browser. Loaded + = (S, e) => browser. Source =New Uri("Sandcu.html",Urikind. Relative );

}

Because no relative path is available in the resource fileUriTherefore, the common practice is to copy the required resources to the independent storage.CreatefileThe function is used to write the resource file into the independent storage with the specified name, which is not described here.

ProgramRunAfter getting up, you can seeSandcu.htmlAlready displayed inWebbrowser.

Currently, the existing cross-platform development frameworks includePhonegapBut the execution efficiency is low.

PassWebbrowserBuilt-inInvokescriptCan be called directly.

Slave HTML5 Code call Native Method

SlaveJSYou can throw a parameter to the bearer browser. The browser processes the parameter after receiving it.

SetSandcu.htmlRewrite InDivOfOnclickThe event is like an external containerWebbrowserThrow the parameter"Sandcu"

In the browserScriptpolicyAdd event handlerBrowser_scriptpolicy()

Windows Phone game ( XNa ) And HTML5 Interaction

Omitted

2.4 phonegap Framework Analysis

Http://www.phonegap.cn/

PhonegapYesreIOSAndAndroidA cross-platform application framework that is widely used on Alibaba Cloud.Windows Phone 7Now supportsMangoLater versions (includingMango)

Structure structure:

The topic program framework andWebFramework Structure,

Third-party class libraries mainly useNewtonsoftOfJSONLibrary

The main program framework consists of local calls and the terminal intermediate layer

 

TheNaticeexecution. TTIs a template file, which can be ignored

PluginAll files under the folder are localAPICall intermediate layer, asynchronousCommandIsHtmlPage call command, passed in the form of parameters, usePhonegapAfter the framework, the default start page isIndex.html, As shown belowMessageBoxTo display device information as an ExamplePhonegapExecute the process.

InLiLabelOnclickEvent bindingNavigator. Notification. Alert ()Function, and specify the information to pop up.

InPhonegap. js(Located inWWWFolder.

Phonegap.exe c =Function(Nativemethodandargs)

{

Window. External. Policy (nativemethodandargs );

};

WhileExecFunctions are uniformly notified in an external browser, and function names and parameters are passed back in the form of string parameters.

InMainpageIn the background codeBrowserscriptpolicyTo process

InProcessjavascriptFunction to analyze the callback parameters. asynchronous callback is used for local calls.InvokescriptMethod to callJSInCallback.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.