I'm working on an Angular app. I have an iFrame and sets its innerHTML which contains relative links, so I decided to append base tag in the head tag of my iFrame, the code I wrote in the script/controller is as follow:
$scope.content = $scope.selectedSitePage.html.value;
var baseTag = document.createElement('base');
var prependURL = "http://232.17.43.22/sharepoint.xyz.net/";
baseTag.href = prependURL ;
$('#frameContent').contents().find('head').append(baseTag);
In HTML:
<iframe id="frameContent" frame-content="content"></iframe>
frameContent is a directive I made:
.directive('frameContent', function () {
return { scope: { "content":"=content" },
link: function link(scope, element) {
element.get(0).contentWindow.document.body.innerHTML = scope.content; } }
});
The ISSUE: is that, if I have a relative URL in img src '/_layout/abc.png', it doesn't appear because the request goes as 'http://232.17.43.22/_layout/abc.png' but it has to be 'http://232.17.43.22/sharepoint.xyz.net/_layout/abc.png'
So my QUESTION, how can I avoid the slicing of the base href after the first slash?