Module: check_mk
Branch: master
Commit: 47554f3a6108b5a78e377aa92784f0a59dc93f60
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=47554f3a6108b5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 5 11:16:32 2011 +0100
Catching javascript errors when pages from other domain are opened in content frame
---
ChangeLog | 1 +
web/htdocs/js/sidebar.js | 51 +++++++++++++++++++++++++++++++++++----------
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a7f7bd8..93804b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -54,6 +54,7 @@
* Fixed header displaying on views when the edit button is not shown to the user
* View pages are not refreshed when at least one form (Filter, Commands,
Display Options) is open
+ * Catching javascript errors when pages from other domain are opened in content
frame
Checks & Agents:
* Fixed problem with OnlyFrom: in Linux agent (df didn't work properly)
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 4fce77b..d132fd6 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -69,17 +69,32 @@ if (window.addEventListener) {
// This is no 100% solution. When moving the mouse out of browser window
// without moving the mouse over the edge elements the dragging is not ended.
function registerEdgeListeners(obj) {
- var edges;
- if(!obj)
- edges = [ parent.frames[1], document.getElementById('side_header'),
document.getElementById('side_footer') ];
- else
- edges = [ obj ];
- for(var i in edges)
- if (window.addEventListener)
- edges[i].addEventListener("mousemove", function(e) { stopDragScroll(e);
snapinTerminateDrag(e); return false; }, false);
- else
- edges[i].onmousemove = function(e) { stopDragScroll(e); snapinTerminateDrag(e);
return false; };
- edges = null;
+ var edges;
+ if (!obj)
+ edges = [ parent.frames[1], document.getElementById('side_header'),
document.getElementById('side_footer') ];
+ else
+ edges = [ obj ];
+
+ for(var i in edges) {
+ // It is possible to open other domains in the content frame - don't
register
+ // the event in that case. It is not permitted by most browsers!
+ if(!contentFrameAccessible())
+ continue;
+
+ if (window.addEventListener)
+ edges[i].addEventListener("mousemove", function(e) {
+ stopDragScroll(e);
+ snapinTerminateDrag(e);
+ return false;
+ }, false);
+ else
+ edges[i].onmousemove = function(e) {
+ stopDragScroll(e);
+ snapinTerminateDrag(e);
+ return false;
+ };
+ }
+ edges = null;
}
/************************************************
@@ -632,13 +647,25 @@ function sidebar_scheduler() {
}
// Detect page changes and re-register the mousemove event handler
// in the content frame. another bad hack ... narf
- if (contentLocation != parent.frames[1].document.location) {
+ if (contentFrameAccessible() && contentLocation !=
parent.frames[1].document.location) {
registerEdgeListeners(parent.frames[1]);
contentLocation = parent.frames[1].document.location;
}
setTimeout(function(){sidebar_scheduler();}, 1000);
}
+// Checks if the sidebar can access the content frame. It might be denied
+// by the browser since it blocks cross domain access.
+function contentFrameAccessible() {
+ try {
+ var d = parent.frames[1].document;
+ d = null;
+ return true;
+ } catch (e) {
+ return false;
+ }
+}
+
function addBookmark() {
href = parent.frames[1].location;
title = parent.frames[1].document.title;