diff --git a/src/Umbraco.Web.UI.Client/src/preview/preview.controller.js b/src/Umbraco.Web.UI.Client/src/preview/preview.controller.js index 78f753a8ca..c282aca3bd 100644 --- a/src/Umbraco.Web.UI.Client/src/preview/preview.controller.js +++ b/src/Umbraco.Web.UI.Client/src/preview/preview.controller.js @@ -106,6 +106,13 @@ var app = angular.module("umbraco.preview", ['umbraco.resources', 'umbraco.servi .fail(function () { console.log("Could not connect to SignalR preview hub."); }); } + function fixExternalLinks(iframe) { + // Make sure external links don't open inside the iframe + Array.from(iframe.contentDocument.getElementsByTagName("a")) + .filter(a => a.hostname !== location.hostname && !a.target) + .forEach(a => a.target = "_top"); + } + var isInit = getParameterByName("init"); if (isInit === "true") { //do not continue, this is the first load of this new window, if this is passed in it means it's been @@ -421,6 +428,7 @@ var app = angular.module("umbraco.preview", ['umbraco.resources', 'umbraco.servi $scope.frameLoaded = true; configureSignalR(iframe); + fixExternalLinks(iframe); $scope.currentCultureIso = $location.search().culture || null; };