diff --git a/bims/static/js/non_requirejs/dashboard_buttons.js b/bims/static/js/non_requirejs/dashboard_buttons.js index b079d3747..7c8b8fae8 100644 --- a/bims/static/js/non_requirejs/dashboard_buttons.js +++ b/bims/static/js/non_requirejs/dashboard_buttons.js @@ -1,3 +1,5 @@ +let closeClicked = false; + function dashboardClose(e, storageKey = '') { let button = $(e.target); if (!button.hasClass('dashboard-close')) { @@ -43,13 +45,30 @@ function dashboardClose(e, storageKey = '') { } else if (previousUrl.indexOf('/abiotic/?') > -1) { window.history.go(-6); } else { + e.preventDefault(); window.history.back(); + closeClicked = true; + return true } } -$(function () { - $('.dashboard-close').click((e) => dashboardClose(e, '')); - $('.site-form-close').click((e) => dashboardClose(e, '')); - $('.sass-form-edit-close').click((e) => dashboardClose(e, 'site-visit-list')); - $('.upload-form-close').click((e) => dashboardClose(e, 'last-map-upload')); +$(document).ready(function () { + attachEventHandlers(); +}); + +$(window).on('pageshow', function () { + attachEventHandlers(); }); + +function attachEventHandlers() { + $('.dashboard-close').off('click').on('click', (e) => dashboardClose(e, '')); + $('.site-form-close').off('click').on('click', (e) => dashboardClose(e, '')); + $('.sass-form-edit-close').off('click').on('click', (e) => dashboardClose(e, 'site-visit-list')); + $('.upload-form-close').off('click').on('click', (e) => dashboardClose(e, 'last-map-upload')); +} + +window.onpopstate = function(event) { + if (closeClicked) { + window.history.back() + } +};