jQuery and Windows 8 JavaScript Metro Style Apps
Asked Answered
I

9

22

Can jQuery be used in Windows 8 Metro-style apps developed using the JavaScript API? I'm looking at the samples, and there's a lot of standard DOM manipulation like document.getElementById, addEventListener, etc. I'd like to use jQuery for productivity.

Ionia answered 14/9, 2011 at 17:20 Comment(3)
I can't see why not. They have a regular javascript runtime, and jQuery is not dependent on a browser (it is widely used in node.js).Gradeigh
I haven't tried yet. Still have to get Windows 8 Developer Preview installed. I was just browsing the docs to get an understanding.Ionia
Already? Eager one you are :)Defunct
I
16

The $ is not magic. jQuery is just a javascript library. It should run fine.

The only thing that might not work are cssHooks which won't take into account any 'quirks' of their environment.

So yes, it will work, if you trust Microsoft to produce an environment that follows the HTML/CSS/JS specifications.

Do you feel lucky?

Imes answered 14/9, 2011 at 17:53 Comment(2)
The "environment" is basically chromeless IE10.Wainwright
init :3 win 8 is like bootablish ie 10 (the metro style Apps)Homeopathic
U
5

Yes, it works, as will any JavaScript library. I verified it on one of the tablets they gave out at the BUILD conference.

However, do not expect to use a CDN to load in the script. You have to download it, add it to the project, and reference it locally.

Upandcoming answered 20/9, 2011 at 4:47 Comment(1)
It wouldn't make sense to use a CDN for a native app anyway - right?Felicio
H
4

tl;dr : you can use jQuery 1.7+, but it's not (yet?) fully integrated when markup modification is involved.


Quote from the Dev Center (msdn)

Using jQuery

You can use jQuery in your Windows Store app using JavaScript, but only versions 1.7 and later. We recommend always using the latest version.

That means that it will work, but you will encounter some non-standard behaviors as listed in the HTML and DOM API changes list (msdn)

There are exceptions mentioned when setting the innerHtml property (among others : Making HTML safer) if there is unsafe markup, but this is non-blocking and the simple fact of loading the jQuery library (1.8.2) will trigger a few.

As mentioned before, you do need to use a local copy of the library (no CDN).

Hochstetler answered 17/11, 2012 at 20:58 Comment(0)
A
2

You can use any JS library. I suspect that methods like WinJS.xhr (aka '$.ajax') where written so that WinJS doesnt have a dependency on jQuery.

Anchylose answered 30/9, 2011 at 4:24 Comment(0)
B
1

It should run fine. jQuery is just a library. The $('#someid') will internally call the document.getElementById You can use it just as if you can use the javascript code you write yourself...

Blench answered 15/9, 2011 at 15:4 Comment(0)
C
1

JQuery should work fine but bear in mind there is some built in functionality for doing this kind of thing, in the case of your example:

WinJS.Utilities.query("#someId li")
     .listen("click", function (result) {

Query Collection Documentation

Cauldron answered 3/8, 2012 at 19:54 Comment(0)
P
1

Don't use any windows libraries like WinJS. Why would you want to lock yourself and be dependent on proprietary code? Stick with the usual stuff, i.e. HTML, CSS, JS(JQuery or otherwise). It will only make your future support/dev far more predictable ...

Pyrexia answered 23/8, 2012 at 13:0 Comment(1)
But what about performance? Surely there is more to winjs than just a javascript library?Manager
G
1

As with all third party JavaScript libraries there are a couple of things you should keep in mind.

I have also written a free Windows Store Gaming Kit that uses third party libraries you can grab the free source for that here: http://win8gamekit.codeplex.com

Guib answered 3/10, 2012 at 14:5 Comment(0)
H
0

Actually you can download it through Visual Studio. If you download NuGet Package Manager.
TOOLS->Add Packages & Extensions

Search the left online packages for NuGet Package Manager and install.

Then when in a project that you want jQuery, right click on your references and add a NuGet package, and search jQuery. That's what I use.

Heartstricken answered 28/11, 2012 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.