Skip to content

Commit

Permalink
js: catch errors earlier when trying to access window.parent or window
Browse files Browse the repository at this point in the history
will result in js errors when framed otherwise.
  • Loading branch information
sni committed Jul 30, 2020
1 parent 39bf57c commit 4ff4142
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
42 changes: 26 additions & 16 deletions root/thruk/javascript/thruk-2.36-1.js
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

/*
Expand All @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions templates/_common_js.tt
Expand Up @@ -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 %]
Expand Down

0 comments on commit 4ff4142

Please sign in to comment.