Navigate to a specific html page on clicking toasts with params (WinJS)

不想你离开。 提交于 2019-12-12 03:24:22

问题


I have a WinJS project and I receive toasts notification from my webservice. In my webservice my XML is like:

 string type = "Computer";
            string toast1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?> ";
            string message = "{\"Message\":{\"Id\":\"6724d22a-87fe-4137-b501-9d9a9a0558b1\",\"DetailId\":\"dc02e784-7832-4625-a538-29be7f885ccb\",\"Description\":\" Message\",\"UserName\":null,\"ActionDateTime\":\"2015-09-15T15:36:14+05:45\",\"CalamityId\":\"c0fa848e-ee6c-4b91-8391-a12058f25387\",\"UseConferenceCalls\":true,\"IsActionCompleted\":false},\"Type\":\"COmp\"}";
          string toast2 = string.Format(@"<toast launch= '{0}'>
                     <visual version='1'>
                         <binding template='ToastText04'>
                             <text id='1'>{1}</text>
                               <text id='2'>{2}</text>
                         </binding>
                     </visual>
                 </toast>", message, "Alert", type);
           string xml = toast1 + toast2;

I want to navigate to a specific html page with the useful json as parameters when user click on toasts. Please suggest me some ways to do this.

Currently I have implemented the following function to handle my toasts.This only works when the app is in active state i.e. running in foreground or background. But when the app is closed completely this function won't hit and failed to meet my requirement.

WinJS.Application.addEventListener("activated", onActivatedHandler, true);

function onActivatedHandler(args) {
    if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
        var messageDetails = (args.detail.arguments).replace(/\\/g, '');
        PhonegapService.setNotificationMessage(messageDetails, function () {
            window.location.href = "page3.html";
        });
    }
}

回答1:


I was facing a similar issue. In my case I was calling functions even before cordova deviceready was fired. From your question not sure if yours is a cordova app or not but make sure all the required javascript files are loaded. You can execute your logic once document is ready. I assume you are using jquery.

function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
    $(document).ready(function(){
    var messageDetails = (args.detail.arguments).replace(/\\/g, '');
    PhonegapService.setNotificationMessage(messageDetails, function () {
        window.location.href = "page3.html";
    });
});
}

}



来源:https://stackoverflow.com/questions/32604236/navigate-to-a-specific-html-page-on-clicking-toasts-with-params-winjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!