WebApp: Cortana loads app, but how can I deep link into the web app with javascript?

可紊 提交于 2019-12-11 08:49:14

问题


For Windows 10: I have started a simple grocery list hosted web application. I went through this quick guide and the app works great. I have added a VCD file, the meta tag on my main page and started on the javascript to handle when Cortana activates the app. The app is registering great with Cortana, I can say: "Grocery show the CostCo list" and Cortana recognizes it and shows the app. The problem is that is always shows the home page. I want to have it show the CostCo page when it is activated with voice asking for that list. I put the pages of the app below, if anything else is needed - please let me know. Thank you.

UPDATE I have tried window.location.href = "costco.php"; and in vorlon it shows in the dom explorer the code on Costco.php but it never makes it to the window. Do I have to do some kind of refresh?

My Home Page on the server

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>Sample page</title>
  <script type="application/javascript">
    (function() {
      if (typeof Windows !== 'undefined') {
        Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function(args) {
          var activation = Windows.ApplicationModel.Activation;
          if (args.kind === activation.ActivationKind.voiceCommand) {
            var speechRecognitionResult = args.result;
            var textSpoken = speechRecognitionResult.text;
            if (speechRecognitionResult.rulePath[0] === "ShowList") {
	if (speechRecognitionResult.semanticInterpretation.properties.apiName[0].search("CostCo") >= 0 || speechRecognitionResult.semanticInterpretation.properties.apiName[0].search("costco") >= 0) {

                // WHAT DO I PUT HERE TO HAVE THE APP GO TO 
                // OR LOAD THE CONTENT FROM HTTP://EXAMPLE.COM/COSTCO.PHP
              } else {
                console.log("No valid stream specified");
              }
            } else {
              console.log("No valid command specified");
            }
          }
        });
      }

    })();
  </script>
  <meta name="msapplication-cortanavcd" content="http://www.example.com/vcd.xml" />
</head>

<body>
</body>

</html>

My VCD File:

<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
  <CommandSet xml:lang="en-us" Name="Grocery">
    <CommandPrefix>Grocery</CommandPrefix>
    <Example>Grocery show CostCo list</Example>
    <Command Name="ShowList">
      <Example>Show {message} list</Example>
      <ListenFor RequireAppName="BeforeOrAfterPhrase">show {apiName} list</ListenFor>
      <Feedback>Loading the {apiName} Grocery list</Feedback>
      <Navigate Target="./COSTCO.PHP"/>
    </Command>
    <PhraseTopic Label="apiName" Scenario="Dictation"></PhraseTopic>
  </CommandSet>
</VoiceCommands>

来源:https://stackoverflow.com/questions/31912247/webapp-cortana-loads-app-but-how-can-i-deep-link-into-the-web-app-with-javascr

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