Skip to content

Commit 3e50d50

Browse files
Merge pull request #4310 from IgorA100/patch-833920
Fix: Firefox return to previous page (skin.js)
2 parents 9bdad92 + af0227e commit 3e50d50

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

web/skins/classic/js/skin.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var icons = {
4141
var panZoomEnabled = true; //Add it to settings in the future
4242
var expiredTap; //Time between touch screen clicks. Used to analyze double clicks
4343
var shifted = ctrled = alted = false;
44+
var mainContent = document.getElementById('content');
4445

4546
function checkSize() {
4647
if ( 0 ) {
@@ -1527,6 +1528,13 @@ function initPageGeneral() {
15271528
alted = e.altKey;
15281529
});
15291530

1531+
if (['montage', 'watch', 'devices', 'reports', 'monitorpreset', 'monitorprobe', 'onvifprobe', 'timeline'].includes(currentView)) {
1532+
mainContent = document.getElementById('page');
1533+
} else if (currentView == 'options') {
1534+
mainContent = document.getElementById('optionsContainer');
1535+
}
1536+
var mainContentJ = $j(mainContent);
1537+
15301538
/* Assigning global handlers!
15311539
** IMPORTANT! It will not be possible to remove assigned handlers using the removeEventListener method, since the functions are anonymous
15321540
*/
@@ -1556,30 +1564,35 @@ function initPageGeneral() {
15561564
});
15571565
}, 200);
15581566

1559-
window.addEventListener('beforeunload', function(event) {
1567+
// https://web.dev/articles/bfcache Firefox has a peculiar behavior of caching the previous page.
1568+
window.addEventListener('pageshow', (event) => {
1569+
if (event.persisted) {
1570+
// Do any checks and updates to the page
1571+
if (mainContentJ[0].clientHeight < 1) {
1572+
window.location.reload( true );
1573+
}
1574+
}
1575+
});
1576+
1577+
window.addEventListener('beforeunload', function addListenerGlobalBeforeunload(event) {
15601578
//event.preventDefault();
1561-
let target;
15621579
/*
15631580
if (!useOldMenuView) {
15641581
closeMbExtruder(updateCookie = true);
15651582
}
15661583
*/
1567-
if (['montage', 'watch', 'devices', 'reports', 'monitorpreset', 'monitorprobe', 'onvifprobe'].includes(currentView)) {
1568-
target = $j('#page');
1569-
} else if (currentView == 'options') {
1570-
target = $j('#optionsContainer');
1571-
} else {
1572-
target = $j('#content');
1573-
}
1574-
if (target.css('display') == 'flex') {
1575-
// If flex-grow is set to a value > 0 then "height" will be ignored!
1576-
target.css({flex: "0 1 auto"});
1577-
}
1584+
if (mainContentJ) {
1585+
if (mainContentJ.css('display') == 'flex') {
1586+
// If flex-grow is set to a value > 0 then "height" will be ignored!
1587+
mainContentJ.css({flex: "0 1 auto"});
1588+
}
15781589

1579-
target.animate({height: 0}, 300, function() {
1580-
$j('body').find('#btn-collapse').css({display: "none"});
1581-
target.css({display: "none"});
1582-
});
1590+
mainContentJ.animate({height: 0}, 300, function rollupBeforeunloadPage() {
1591+
const btnCollapse = $j('body').find('#btn-collapse');
1592+
if (btnCollapse) btnCollapse.css({display: "none"});
1593+
mainContentJ.css({display: "none"});
1594+
});
1595+
}
15831596
//event.returnValue = '';
15841597
});
15851598
}

0 commit comments

Comments
 (0)