locked
NavBar kills eventhandlers when navigating on current page

    Question

  • Hi Folks,

    I'm developing an app with 5 pages and I navigate with a Nav Bar. I integrated the NavBar in the Default.html. It works fine for me, but I have a Problem when the user navigates to the page on which he currently is:

    No eventhandler fires. I found out, that the app creates a second instance of the page which kills the handlers? Is this right?

    Is there a way to prevent this? - Except from integrating an own NavBar on every page?

    Hope you understand my question

    Thanks a lot

    Dragon, Germany

    Friday, May 23, 2014 10:52 AM

Answers

  • I don't think reloading the same page is supported in navigator.js, at least by default. You can check the WinJS.Navigation.location property, and avoid reloading the page if it hasn't changed. If you want to re-run code from your ready() function, refactor that code to a separate function and call the new function instead of reloading the page.
    Friday, May 23, 2014 9:58 PM

All replies

  • I don't think reloading the same page is supported in navigator.js, at least by default. You can check the WinJS.Navigation.location property, and avoid reloading the page if it hasn't changed. If you want to re-run code from your ready() function, refactor that code to a separate function and call the new function instead of reloading the page.
    Friday, May 23, 2014 9:58 PM
  • I also ran into this problem awhile back. I found that it was because the unload fired after the ready, which unloaded the event handlers. Apparently it was because the windows 8.1 navigator.js was designed this way. The fix I used was to use the windows 8 navigator script which did not do that. Here's the thread that I found this solution from

    http://social.msdn.microsoft.com/Forums/en-US/0b3f8af3-6fd8-44bf-b47b-9541a978b76d/ready-function-fires-before-unload?forum=winappswithhtml5

    Sunday, May 25, 2014 4:26 PM
  • To call unload in the old page before calling ready on the new page, you can also use the navigator.js customization described in this topic:

    http://msdn.microsoft.com/en-us/library/windows/apps/dn743861.aspx

    Tuesday, May 27, 2014 3:48 PM