From 4ff4142fd513bf54c0bcaaec17638b3a4ca7bd63 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 30 Jul 2020 18:01:33 +0200 Subject: [PATCH] js: catch errors earlier when trying to access window.parent or window will result in js errors when framed otherwise. --- root/thruk/javascript/thruk-2.36-1.js | 42 +++++++++++++++++---------- templates/_common_js.tt | 8 ++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/root/thruk/javascript/thruk-2.36-1.js b/root/thruk/javascript/thruk-2.36-1.js index f4407dc08b..24165dccc9 100644 --- a/root/thruk/javascript/thruk-2.36-1.js +++ b/root/thruk/javascript/thruk-2.36-1.js @@ -208,15 +208,19 @@ function bodyOnLoad(refresh) { scrollToPos = 0; } if(refresh) { - if(window.parent && window.parent.location && String(window.parent.location.href).match(/\/panorama\.cgi/)) { - stopRefresh(); - jQuery("#refresh_label").html(""); - } else if(String(window.location.href).match(/\/panorama\.cgi/)) { - stopRefresh(); - jQuery("#refresh_label").html(""); - } else { - setRefreshRate(refresh); - jQuery(window).bind("mousewheel DOMMouseScroll click keyup", updateLastUserInteraction); + try { + if(window.parent && window.parent.location && String(window.parent.location.href).match(/\/panorama\.cgi/)) { + stopRefresh(); + jQuery("#refresh_label").html(""); + } else if(String(window.location.href).match(/\/panorama\.cgi/)) { + stopRefresh(); + jQuery("#refresh_label").html(""); + } else { + setRefreshRate(refresh); + jQuery(window).bind("mousewheel DOMMouseScroll click keyup", updateLastUserInteraction); + } + } catch(err) { + console.log(err); } } @@ -761,6 +765,7 @@ function updateUrl() { /* reloads the current page and adds some parameter from a hash */ function reloadPage() { + stopRefresh(); window.clearTimeout(refreshTimer); var obj = document.getElementById('refresh_rate'); if(obj) { @@ -774,13 +779,13 @@ function reloadPage() { } /* set reload mark in side frame */ - if(window.parent.frames && top.frames && top.frames['side']) { - try { + try { + if(window.parent.frames && top.frames && top.frames['side']) { top.frames['side'].is_reloading = newUrl; } - catch(err) { - console.log(err); - } + } + catch(err) { + console.log(err); } /* @@ -796,8 +801,13 @@ function reloadPage() { } function reloadNav() { - if(parent.frames[0] != null) { - parent.frames[0].location.reload(); + try { + if(parent.frames[0] != null) { + parent.frames[0].location.reload(); + } + } + catch(err) { + console.log(err); } } diff --git a/templates/_common_js.tt b/templates/_common_js.tt index 35ddd974dd..8d906510f2 100644 --- a/templates/_common_js.tt +++ b/templates/_common_js.tt @@ -64,11 +64,11 @@ } [% END %] [% IF use_frames && use_dynamic_titles %] - if(window.parent.frames && !String(window.parent.location.href).match(/\/panorama\.cgi/)) { - try { + try { + if(window.parent.frames && !String(window.parent.location.href).match(/\/panorama\.cgi/)) { window.parent.document.title = '[% escape_quotes(title_prefix) %][% escape_quotes(title) %]'; - } catch(err) { console.log(err) } - } + } + } catch(err) { console.log(err) } [% END %] [% IF bodyonload %]