如何在组件角度打开外部站点?

时间:2019-07-08 14:43:42

标签: angular

我有个主意,但我不知道如何实现。

我有一个应用程序(angular + electron + sqlite),它在数据库上运行,当前执行一个脚本,该脚本从某个页面检索数据(脚本的描述(www.Cisowscy.com/Software/haploFT),然后将这些文件手动添加到应用程序中,然后在处理后将它们添加到数据库中,稍后应用程序将在该数据库上进行分析。

我希望避免转到第二个窗口(谷歌浏览器)并执行此脚本。我希望用户能够在组件内部显示自己选择的项目,而应用程序将从中下载用户所需的数据,然后由他们自行处理,依此类推。 (现在)。

问题是如何强制外部网站(从外部站点)装入(隔离?)盒子(此子组件)?

以及如何从父组件进入此加载页面的“ DOM”。

以及如何在关闭组件时从此页面加载的大量数据释放内存。

有人应该对如何开始...,如何开始有所了解?

非常感谢您的帮助。 P.s.我一天半在Google上寻找一些想法,但没有成功。


为什么@stackoverflow .com骚扰我?他们给了我一个蓝色的领域“一个您在公共Stack Overflow上不能问的问题?了解有关与Team Stack Overflow共享私人信息的更多信息。”标签,但在我的问题中,没有任何东西可以定义它。 ?为什么?!

1 个答案:

答案 0 :(得分:1)

尝试:-

.html

 <iframe id="" class="" height="100%" width="100%" style="border: 0;" [src]="urlSafe"></iframe>

DomSanitizerPipe.pipe.ts

@Pipe({
    name: 'domSanitizer'
})
export class DomSanitizerPipe implements PipeTransform {

    constructor(protected sanitizer: DomSanitizer) { }
    transform(htmlString: string, args?: any): any {
        return this.sanitizer.bypassSecurityTrustHtml(htmlString);
    }

}

.ts

   constructor(
        public sanitizer:DomSanitizer
    ) { 
        this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl('https://.....');
    }

2)从父组件进入此加载页面的“ DOM”。

.ts

window.parent.someMethodDefinedInOpenWindow(data);

//someMethodDefinedInOpenWindow is defined in electron app/ other iframe loaded //app

3)从iframe应用中的component.ts中定义调用方法

index.html

     <app-root></app-root>
        <script type="text/javascript">
//updateFromDevice is called from iframe
            function updateFromDevice(data) {
                window['componentRef'].zone.run(() => {
                    window['componentRef'].component.updateFromIframe(data);
                });
            }
        </script>

app.component.ts

 constructor(
        private zone: NgZone,
    ) {
        window['componentRef'] = {
            zone: this.zone,
            componentFn: (value) => this.updateFromIframe(value),
            component: this
        };
    }

  updateFromIframe(data) {}
相关问题