This is a migrated thread and some comments may be shown as answers.

Can I tell if the view is being shown because the user went back in the show event?

1 Answer 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan M
Top achievements
Rank 1
Jonathan M asked on 13 Nov 2012, 03:22 PM
We've run into a situation where we need to be able to tell if a view is being shown because the user clicked 'back' (whether via an HTML button, or the back button on their device/browser). Is there any way to do this from within the view's show event?

Thanks,
Jonathan

1 Answer, 1 is accepted

Sort by
0
Jonathan M
Top achievements
Rank 1
answered on 12 Dec 2012, 11:03 PM
I was able to get this working by adding the following code right after the app initialization:
kendo.history.change(function (e) {
    app.isBrowserBack = true;
});
 
$(function () {
    var lastHistoryLength = app.pane.history.length;
 
    app.pane.bind('navigate', function (opt) {
        app.isBack = app.isBrowserBack || lastHistoryLength > app.pane.history.length;
        app.isBrowserBack = false;
        lastHistoryLength = app.pane.history.length;
    });
});

Now I can tell if a view is being shown due to clicking a back button like this:
function show() {
    if (!app.isBack) {
         // Do stuff that we only want to do on forward navigation,
            // like load data from a web server
    }
    // Do common view show logic
}

This code has some limitations. The biggest being that it only works if you aren't using multiple panes (think phone apps and not tablet apps), but it works for our project. If anyone has any ideas for a more general-purpose solution, I'm all ears.

Jonathan
Tags
General Discussions
Asked by
Jonathan M
Top achievements
Rank 1
Answers by
Jonathan M
Top achievements
Rank 1
Share this question
or