From c5753a013c6eaae3413a8f5732364501d3186e5d Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 6 Jul 2016 13:28:51 +0100 Subject: [PATCH] Handle DOMException when embedded in an iframe of different origin Fixes #932 --- editor/js/ui/view.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/editor/js/ui/view.js b/editor/js/ui/view.js index bfbb48f45..36289c218 100644 --- a/editor/js/ui/view.js +++ b/editor/js/ui/view.js @@ -2162,10 +2162,19 @@ RED.view = (function() { } function focusView() { - var scrollX = window.parent.window.scrollX; - var scrollY = window.parent.window.scrollY; - $("#chart").focus(); - window.parent.window.scrollTo(scrollX,scrollY); + try { + // Workaround for browser unexpectedly scrolling iframe into full + // view - record the parent scroll position and restore it after + // setting the focus + var scrollX = window.parent.window.scrollX; + var scrollY = window.parent.window.scrollY; + $("#chart").focus(); + window.parent.window.scrollTo(scrollX,scrollY); + } catch(err) { + // In case we're iframed into a page of a different origin, just focus + // the view following the inevitable DOMException + $("#chart").focus(); + } } /**