Javascript windows phone 8的Cordova问题
在visual studio 2013中使用cordova时,我遇到了两个似乎无法找到有效解决方案的问题。在config.xml中,我指定方向应为纵向模式,代码如下:Javascript windows phone 8的Cordova问题,javascript,cordova,windows-phone-8,Javascript,Cordova,Windows Phone 8,在visual studio 2013中使用cordova时,我遇到了两个似乎无法找到有效解决方案的问题。在config.xml中,我指定方向应为纵向模式,代码如下: <preference name="Orientation" value="portrait" /> (function () { "use strict"; document.addEventListener('deviceready', onDeviceReady.bind(this), fal
<preference name="Orientation" value="portrait" />
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
document.addEventListener("backbutton", onBackKeyDown, false);
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
function onBackKeyDown() {
history.go(-1);
navigator.app.backHistory();
};
})();
if (device.platform == "windows") {
// Get the back button working in WP8.1
WinJS.Application.onbackclick = function () {
onBackKeyDown();
return true; // This line is important, without it the app closes.
}
}
else {
document.addEventListener("backbutton", onBackKeyDown, false);
}
同样,它在Android上运行得很好,但是在WindowsPhone8上,backbutton事件似乎根本没有被调用。我在函数中输入的任何内容似乎都无法运行。因此,它似乎忽略了侦听器或不使用它
关于如何使用cordova使此代码在windows phone 8上正常工作,您有什么想法吗?关于方向问题:cordova在创建Visual Studio项目时似乎正在删除config.xml方向设置。在package.phone.appxmanifest文件(适用于WP 8.1)中,您希望在部分中包含以下内容: Windows Phone 8(C#):
我已经找到了一种方法,可以让back按钮与cordova和wp8.1一起工作。这需要使用WinJS框架 在ondeviceready函数中,使用以下代码:
<preference name="Orientation" value="portrait" />
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
document.addEventListener("backbutton", onBackKeyDown, false);
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
function onBackKeyDown() {
history.go(-1);
navigator.app.backHistory();
};
})();
if (device.platform == "windows") {
// Get the back button working in WP8.1
WinJS.Application.onbackclick = function () {
onBackKeyDown();
return true; // This line is important, without it the app closes.
}
}
else {
document.addEventListener("backbutton", onBackKeyDown, false);
}
然后使用onBackKeyDown函数来处理调用:
function onBackKeyDown() {
// Back key pressed, do something here
};
在玩了一下merges文件夹之后。我发现后退按钮问题只影响windows phone 8.1。“后退”按钮导航在windows phone 8上运行良好。但是,windows phone 8和8.1上仍然存在旋转屏幕问题。此代码在windows phone 8.1上非常有效,但在windows phone 8.0上不起作用。有什么想法吗?嘿@Chris,WP8只是有点不同,我已经更新了答案。我是古玩,你在Windows Phone 8.1中是否触发了“暂停”和“恢复”事件?
function onBackKeyDown() {
// Back key pressed, do something here
};