简体   繁体   English

通过单击IFrame(内联框架)中的项目,我需要路由到特定的URL

[英]By clicking an item in IFrame (Inline Frame) i need to route to specific URL

Hi am using i frame in one component of my angular 2 application. 嗨,我在我的angular 2应用程序的一个组件中使用了i frame。

Component.ts Component.ts

import { Component, OnInit } from '@angular/core';
import { SafeResourceUrl,DomSanitizer,} from '@angular/platform-browser';

@Component({
  selector: 'sample comp',
  templateUrl: './sample-comp.component.html',
  styleUrls: ['./sample-comp.component.css']
})
export class sampleComp implements OnInit {
  //DECLARATION
  webURL:SafeResourceUrl;
  constructor() { 

  }

  ngOnInit() {
  }
public onSelectid(){
  console.log('Router selected');

}
}
let greeter = new CampaignOrderComponent();
module FooModule {  
    export var FooInstance = new CampaignOrderComponent();
}

Component.html Component.html

<iframe src="http://sampleurl" width="100%" height="600" style="margin-top:-10px" frameborder="0"
    webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>

While triggering a click event on i frame, i need to route to another component.(which i had already specified at my root component's routing file). 在i框架上触发click事件时,我需要路由到另一个组件。(我已经在根组件的路由文件中指定了该组件)。

Right now inside the i frame app (a mvc app) i had triggered a click function 现在 iframe应用程序 (一个mvc应用程序)中,我已经触发了点击功能

parrent.showme()

and added index.js on root folder of angular 2 app (linked with index.html) 并在angular 2应用程序的根文件夹上添加了index.js(与index.html链接)

index.js index.js

  function showme()
  {
       alert('function called');
       FooModule.FooInstance.onSelectid();

  }

now i can show alert on the angular 2 app page via clicking inside the i frame app. 现在,我可以通过在i frame应用程序内部单击来在angular 2应用程序页面上显示警报。

The target is to change the functionality of the showme() to change the route of the angular 2 app. 目标是更改showme()的功能以更改angular 2应用程序的路由。

How can i do it ? 我该怎么做 ?

i had tried several methods to solve it, unfortunately i cant get any. 我尝试了几种方法来解决它,不幸的是我什么也做不了。

Add id to your frame and then use contentWindow.document.body.onclick on iframe element 将ID添加到您的框架中,然后使用contentWindow.document.body.onclick iframe元素

   <iframe id="iframe_id" src="https://sampleurl" style="margin-top:-10px" frameborder="1"
        webkitallowfullscreen mozallowfullscreen allowfullscreen>
    </iframe>

 constructor(private _router: Router){
  } 
  ngAfterViewInit(){
    document.getElementById("iframe_id").contentWindow.document.body.onclick = 
      () => {
      this._router.navigate(['/yourChildRoute']);
      }


   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过点击网址打开iframe - how to open iframe by clicking a url 当该网址不允许在iframe中时,我需要重定向到该网址? - I need to redirect to a url, when the url not allowed to be inside a iframe? 如果我需要将外部网址加载到网页中,是否可以使用iframe替代 - Are there any alternatives for an IFrame if I need to load an external url to my webpage 我需要访问 iframe 视频中的一个特定元素吗? - I need to access one specific element inside iframe video? 拒绝在框架中显示“URL”,因为它将“x-frame-options”设置为“拒绝”。 但我没有使用 iFrame - Refused to display 'URL' in a frame because it set 'x-frame-options' is set to 'deny'. But i am not using iFrame 特定网址的角度路线 - Angular Route for specific url 如果iframe网址更改,则更改父框架网址 - Change parent frame url if iframe url changes 在父级中单击某些内容时,如何将URL地址从父级传递到iframe? - how do i pass a URL address from a parent to iframe when clicking on something in the parent? Fastify 路线不适用于特定的 url - Fastify route not working with specific url 我有 2 个 UI 选项卡。 我需要在单击该选项卡外的按钮时激活一个特定选项卡 - I have 2 UI tabs. I need to activate one specific tab on clicking a button outside that tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM