我需要基本回調函數的幫助。我有一個主要的index.html文件引用script.js。在index.html裏面,它只是調用app.initialize();從script.js初始化函數。下面是下面的script.js代碼:被基本回調函數困惑
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
tokenHandler:function(msg) {
console.log("Token Handler " + msg);
alert(msg);
},
errorHandler:function(error) {
console.log("Error Handler " + error);
alert(error);
},
// result contains any message sent from the plugin call
successHandler: function(result) {
alert('Success! Result = '+result)
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var pushNotification = window.plugins.pushNotification;
// TODO: Enter your own GCM Sender ID in the register call for Android
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(this.successHandler, this.errorHandler,{"senderID":"SENDER ID HERE","ecb":"app.onNotificationGCM"});
}
else {
pushNotification.register(this.tokenHandler,this.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
}
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
// iOS
onNotificationAPN: function(event) {
var pushNotification = window.plugins.pushNotification;
console.log("Received a notification! " + event.alert);
console.log("event sound " + event.sound);
console.log("event badge " + event.badge);
console.log("event " + event);
if (event.alert) {
navigator.notification.alert(event.alert);
}
if (event.badge) {
console.log("Set badge on " + pushNotification);
pushNotification.setApplicationIconBadgeNumber(this.successHandler, event.badge);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
},
// Android
onNotificationGCM: function(e) {
switch(e.event)
{
case 'registered':
if (e.regid.length > 0)
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
alert('registration id = '+e.regid);
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
PushWoosh.appCode = "CODE GOES HERE";
PushWoosh.register(e.regid, function(data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function(errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
if (e.foreground)
{
alert(e.payload.message);
alert(e.payload.pagenotification);
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if (e.coldstart)
{
alert(e.payload.message);
alert(e.payload.pagenotification);
}
else
{
alert(e.payload.message);
alert(e.payload.pagenotification);
}
}
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
};
內onNotificationGCM的,對在任的前景/冷啓動情況「消息」的情況下,我想要重新回到e.payload.pagenotification主索引調用app.initialize()的.html頁面。有沒有什麼方法可以解釋我如何將這些信息返回到索引頁面。
任何幫助將不勝感激,謝謝! - 全天候