locked
Closing Windows Store application programatically (WinJS)

    Question

  • I have a Windows Store-app in JavaScript that mostly functions for its live tile. It fetches news from a news source and displays the latest news through the live tile. When the user clicks the app, the user gets redirected to an internal site in their default browser. The problem is that the app persists after it has opened the redirect link in the default browser. Seeing as the app has fulfilled it's work by then, I would like to close the app after the redirect has happened. Or at least remove it from the taskbar so that it doesn't redirect again if the user clicks the app again. I've looked around, but I can only find a test method in C# that does the trick. Seeing as this is with JavaScript I was hoping there is a solution.
    Thursday, September 11, 2014 1:00 PM

Answers

  • Note that programmatically closing the app will appear as an app crash.

    See the remarks at http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj569366.aspx

    Using the close method in a Windows Store app using JavaScript

    Invoking the window.close method on a Windows Store app using JavaScript closes the app without prompting the user.

    It is against Windows Store policy to programmatically close your app. The only time an app should programmatically close is when there is an unrecoverable error, in which case the app should throw an unhandled exception or  use the MSApp.terminateApp method.

    In you use window.close, it appears as a crash to the user is logged as a crash in the developer’s telemetry data on the Windows Store dashboard.

    • Marked as answer by Andrnes Friday, September 12, 2014 8:35 AM
    Friday, September 12, 2014 8:24 AM
    Moderator

All replies

  • Try this:

     

    <ahref="http://www.microsoft.com"target="_blank"onclick="self.close()">Open new link in browser</a>


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, September 11, 2014 7:18 PM
    Moderator
  • Note that programmatically closing the app will appear as an app crash.

    See the remarks at http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj569366.aspx

    Using the close method in a Windows Store app using JavaScript

    Invoking the window.close method on a Windows Store app using JavaScript closes the app without prompting the user.

    It is against Windows Store policy to programmatically close your app. The only time an app should programmatically close is when there is an unrecoverable error, in which case the app should throw an unhandled exception or  use the MSApp.terminateApp method.

    In you use window.close, it appears as a crash to the user is logged as a crash in the developer’s telemetry data on the Windows Store dashboard.

    • Marked as answer by Andrnes Friday, September 12, 2014 8:35 AM
    Friday, September 12, 2014 8:24 AM
    Moderator