How to load a external html file?

邮差的信 提交于 2019-12-24 16:13:12

问题


I just want to load a .html file into a JS view in my UI5 Application. This file is an external page that contains some charts..

I'm trying many things, but no success..

Thank you very much if anyone could help me on that.


回答1:


What were those "many things" you tried?

The general approach is to embed the other HTML page as an iframe, using the sap.ui.core.HTML control, see this example: http://jsbin.com/dutuparedeyu/1/edit?html,output

new sap.ui.core.HTML({
  preferDOM: true,
  content: "<iframe src='http://www.sap.com'></iframe>"
});

Depending on the HTML page you could alternatively load it with an Ajax call, extract the HTML you want to display and also display it with the sap.ui.core.HTML control. But this approach gets difficult when the other page has scripts and CSS loaded in the head that you would also have to load into your application page.




回答2:


For the sake of completeness: Here is a solution for an XML fragment:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml">
    <Dialog title="Example" contentWidth="90%" contentHeight="90%" 
            horizontalScrolling="false" verticalScrolling="false" class="iframeHolder">
        <html:iframe src="http://www.example.com" height="100%" width="100%"/>
        <buttons>
            <Button text="{i18n>Button.ok}" press="closeDialog"/>
        </buttons>
    </Dialog>
</core:FragmentDefinition>

with this CSS rule to stretch the iframe to the total height of the Dialog

.iframeHolder .sapMDialogScrollCont {
    width: 100%;
    height: 100%;
    padding: 0;
}

(Yes, I know that Diego asked for a JS view)



来源:https://stackoverflow.com/questions/26344165/how-to-load-a-external-html-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!