Reputation: 3
new to SO, and sorry if this has been already answered!
Anyway, I'm starting to learn how to develop Windows Store Apps, and our first assignments have to be developed in JavaScript/HTML5. So, I need to use WinJS.Namespace.define for this particular project but it doesn't seem to work for me.
I'm trying to create a button that displays a text when pressed in hello.html (/pages/hello/hello.html):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>hello</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.2.0/js/base.js"></script>
<script src="//Microsoft.WinJS.2.0/js/ui.js"></script>
<link href="/css/default.css" rel="stylesheet"/>
<link href="hello.css" rel="stylesheet" />
<script src="hello.js"></script>
<body>
<div class="hello fragment">
<header aria-label="Header content" role="banner">
<button data-win-control="WinJS.UI.BackButton"></button>
<h1 class="titlearea win-type-ellipsis">
<span class="pagetitle">TotalExam</span>
</h1>
</header>
<section aria-label="Main content" role="main">
<fieldset>
<legend>Inicio de sesión</legend>
<input id="dfEntrar" type="button" value="Entrar" />
</fieldset>
<div id="prueba"></div>
</section>
</div>
</body>
hello.js (/pages/hello/hello.js) has the following code:
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/hello/hello.html", {
ready: function (element, options) {
Accion.Loguear();
},
});
})();
and finally, acciones.js (/js/MyScripts/acciones.js) contains the namespace definition and code for the text:
(function () {
WinJS.Namespace.define("Accion", {
Loguear: fLogin
});
$ = function (val) {
return document.querySelector(val);
};
function fLogin() {
$("#dfEntrar").addEventListener("click", function() {
$("#prueba").innerText = "Probando...";
});
};
});
What am I doing wrong? Thanks in advance!
Upvotes: 0
Views: 624
Reputation: 59773
You're not loading the script file ("/js/MyScripts/acciones.js"
) onto the page. A WinJs application does not automatically load scripts.
Before loading hello.js
add another script
tag to load the other file:
<link href="hello.css" rel="stylesheet" />
<script src="/js/MyScripts/acciones.js"></script>
<script src="hello.js"></script>
Upvotes: 1