简体   繁体   English

如何在我的 Angular 组件中打开其他 web 站点

[英]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.

相关问题 How can I use my logo slider JavaScript function inside an Angular component / TypeScript? - How can I use my logo slider JavaScript function inside an Angular component / TypeScript? 我可以自定义在另一个 Web 组件中使用的 Web 组件的 css 吗? - Can I custom css of my web-component used inside another web-component? 如何在我的React网站中使用浮动按钮? - How can i use floating button in my react web site? 我如何将Outlook Web App嵌入我的网站? - How i can embed Outlook Web App into my site? 如何在组件内使用Angular 2 Material Sidenav? - How can I use Angular 2 Material Sidenav inside a component? 如何使用 angular 在我的组件中使用 datePipe? - how can I use datePipe in my component using angular? 我如何在其他组件内使用我的增量值 - How do i use my incremented value inside inside an other component 如何成功路由到 Angular 中的其他组件? - How can I successfully route to my other components in Angular? 如何从 Angular 8 中的其他组件打开引导模式窗口? - How to open a bootstrap modal window from other component in Angular 8? 如何在网站上将Winjs 4.4.0用作jQueryUI或其他UI框架 - how can I use winjs 4.4.0 in the web site as jQueryUI or other UI framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM