Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在单击按钮时将网站加载为Iframe并将参数传递给它';s URL的角度_Javascript_Html_Angular_Typescript - Fatal编程技术网

Javascript 如何在单击按钮时将网站加载为Iframe并将参数传递给它';s URL的角度

Javascript 如何在单击按钮时将网站加载为Iframe并将参数传递给它';s URL的角度,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,所以我有两个不同的角度项目。一个是登录页网站,另一个是图书销售网站 登录页组件的URL()中有路由参数和一个按钮: <button type="button" class="btn btn-primary">Buy Books</button> 买书 我想这个按钮加载其他网站的书籍作为iframe出售,同时也传递路由参数到它的URL,点击 有人知道我该怎么做吗 你需要走好几步才能到达那里 为按钮mouseup或单击事件绑定事件处理程序 获取当前路由器端点并将其附加到i

所以我有两个不同的角度项目。一个是登录页网站,另一个是图书销售网站

登录页组件的URL()中有路由参数和一个按钮:

<button type="button" class="btn btn-primary">Buy Books</button>
买书
我想这个按钮加载其他网站的书籍作为iframe出售,同时也传递路由参数到它的URL,点击


有人知道我该怎么做吗

你需要走好几步才能到达那里

  • 为按钮
    mouseup
    单击
    事件绑定事件处理程序
  • 获取当前路由器端点并将其附加到iframe url
  • 清理iframe url
  • 设置布尔标志以显示iframe
  • 组成部分

    从'@angular/core'导入{Component,OnInit,OnDestroy};
    从'@angular/Router'导入{NavigationEnd,Router};
    从“@angular/platform browser”导入{domsanizer};
    @组成部分({
    选择器:'应用程序根',
    templateUrl:“./app.component.html”,
    样式URL:['./app.component.css']
    })
    导出类AppComponent实现OnInit、OnDestroy{
    iframeUrl:string;
    showIframe=false;
    路由订阅:任何;
    构造函数(专用_路由器:路由器,专用_消毒剂:DOMSANTIZER){}
    恩戈尼尼特(){
    }
    公共鼠标(事件:任意){
    this.routerSubscription=this.\u router.events.filter(e=>e instanceof NavigationEnd).subscription(
    事件=>{
    this.iframeUrl=“指向iframe的url/”+事件['urlAfterRedirects'];
    this.iframeUrl=this.\u sanitizer.bypassSecurityTrustResourceUrl(this.iframeUrl);
    this.showIframe=true;
    }
    );
    }
    恩贡德斯特罗(){
    if(此.routerSubscription){
    this.routerSubscription.unsubscribe();
    }
    }
    }
    
    模板

    <button type="button" class="btn btn-primary" (mouseup)="mouseUp($event)">Buy Books</button>
    
    <ng-container *ngIf="showIframe">
      <iframe [src]="iframeUrl" width="100%" height="100%" frameBorder="0" scrolling="no">Alternative text</iframe>
    </ng-container>
    
    买书
    备选案文
    
    我不能按照你解释的方式做。但我使用了你在这里提出的一些想法。我将订阅的激活路由中的url作为this.iframeUrl传递。所以我有这样的东西。iframeUrl=
    url到iframe${params}/
    这样,它可以根据浏览器中的url参数显示不同的数据。谢谢你的回答。这真的很有帮助,不客气。它只是一个占位符。这个问题一开始有点模糊。您说URL有一个参数,但您提到的示例URL不包含任何参数。所以我很自然地认为您想要使用URL端点。