[英]How I can open other web site inside my Angular Component
I am trying to make a web application that should open a web site inside a component then the tool will act like selenium. The senerio like this.我正在尝试制作一个 web 应用程序,该应用程序应该在组件内打开一个 web 站点,然后该工具将像 selenium 一样运行。像这样的 senerio。 User type link and hit enter.
用户键入链接并按回车键。 Then we open the web page inside the component.
然后我们打开组件内部的web页面。 There is several ways to open a web page inside it like Iframe, embed, object etc. But here is the thing the web pages block me because of the
CORS POLICY
So is there way to achive this.有几种方法可以打开其中的 web 页面,例如 Iframe、嵌入、object 等。但由于
CORS POLICY
,web 页面阻止了我,所以有没有办法实现这一点。 Thank you.谢谢你。
You need to use dom sanitizer and your cross domain should accept your request through iframe.你需要使用 dom sanitizer 并且你的跨域应该通过 iframe 接受你的请求。
Here is an example stackblitz.这是一个示例 stackblitz。 https://stackblitz.com/edit/angular-158g4a
https://stackblitz.com/edit/angular-158g4a
import { Component } from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
constructor(private domSanitizer: DomSanitizer){}
//https://www.google.com/ // does not work
//https://angular.io/ // works fine
url = this.domSanitizer.bypassSecurityTrustResourceUrl('https://angular.io/')
name = 'Angular';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.