我正在尝试使用rest服务获取带有javascript的html (在这个javascript脚本标记内具有相对路径),并将其显示在我的angularjs应用程序的iFrame中。
基本上,我们与webfocus集成,当我们调用rest服务时,webfocus提供html内容。此html内容中包含script标记,并且此script标记具有相对路径。因此,当我尝试将html/javascript绑定到iFrame contentWindow.document.body时,我遇到了相对路径问题。
任何帮助都将不胜感激。
Angularjs指令如下。
.directive("preview", ['$sce',function ($sce) {
function link(scope, element) {
var iframe = document.createElement('iframe');
iframe.setAttribute("id", "ifWebFocusContent");
iframe.setAttribute("name", "nameWebFocusContent");
var element0 = element[0];
element0.appendChild(iframe);
var body = iframe.contentWindow.document.body;
//var body = iframe.document.body;
scope.$watch('content', function () {
body.innerHTML = $sce.trustAsHtml(scope.content);
});
}
return {
link: link,
restrict: 'E',
scope: {
content: '='
}
};
}])
超文本标记语言代码是<preview content="reportHtml"></preview>
发布于 2018-09-30 04:11:45
当我在iframe中添加基本标签时,问题得到了解决,因为here也在watch中使用了这3行代码,而不是分配内部html。
iframe.contentWindow.document.open();
iframe.contentWindow.document.write($sce.trustAsHtml(scope.content));
iframe.contentWindow.document.close()
https://stackoverflow.com/questions/52565458
复制相似问题