Make sure external links are not attempted to be opened inside preview iframe

This commit is contained in:
Rowan Bottema
2020-10-03 20:12:33 +02:00
committed by Nathan Woulfe
parent 2d785af821
commit a10477a72d

View File

@@ -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;
};