簡體   English   中英

如何在iFrame中使用javascript包含外部html

[英]how to include an external html with javascript in iFrame

我正在嘗試使用rest服務使用javascript(帶有此javascript腳本標記內的相對路徑)獲取html,並將其顯示在我的angularjs應用程序的iFrame中。

基本上,我們正在與webfocus集成,並且在調用rest服務時,webfocus提供html內容。 該html內容中包含腳本標簽,並且此腳本標簽具有相對路徑。 因此,當我嘗試將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: '='
        }
    };
}])

HTML代碼是<preview content="reportHtml"></preview>

我使用此鏈接編寫此代碼。

當我在iframe中添加基礎標簽,因為它得到了解決這里也用這3個行內的手表,而不是分配給內部HTML。

 iframe.contentWindow.document.open();
                iframe.contentWindow.document.write($sce.trustAsHtml(scope.content));
                iframe.contentWindow.document.close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM