locked
Event when fragment is unloaded? RRS feed

  • Question

  • In a Metro Style App, I can add an event listener when a fragment is loaded:

    WinJS.Application.addEventListener('fragmentappended', function handler(e)

    how do I attach an event listener for when the fragment is removed or unloaded?

    Thanks,

    Michael


    Michael S. Scherotter
    Principal Architect Evangelist Microsoft Corporation,
    Blog, Twitter, Facebook

    Friday, December 30, 2011 12:42 AM

All replies

  • Hi Michael,

    How are you unloading the fragment?

    -Jeff


    Jeff Sanders (MSFT)
    Friday, December 30, 2011 2:02 PM
    Moderator
  • WinJS.Navigation.back();


    Michael S. Scherotter
    Principal Architect Evangelist Microsoft Corporation,
    Blog, Twitter, Facebook

    Friday, December 30, 2011 5:00 PM
  • Hi Michael,

    I am not sure exactly what you are looking for...  The fragmentappended event is created by you (or the templates) when you take action such as navigating and add the fragment... it is not fired by default when a fragment is appended.  For example the templates do this for you:

    WinJS.Application.queueEvent({ type: 'fragmentappended', location: e.detail.location, fragment: host, state: e.detail.state });

    The fragment is appended to the DOM and is not itself an object.  You could add a <div> with some sort of id or something to each fragment and you could use that for some sort of notification when you are replacing the fragment.  Since you know when you are replacing fragments I am not sure why you would need an unload event.  Can you provide some more details about what you are trying to accomplish?

    -Jeff


    Jeff Sanders (MSFT)
    Friday, December 30, 2011 5:53 PM
    Moderator