通过单击IFrame(内联框架)中的一个项目,我需要路由到特定的URL
By clicking an item in IFrame (Inline Frame) i need to route to specific URL
我在angular 2应用程序的一个组件中使用了i frame。
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
<iframe src="http://sampleurl" width="100%" height="600" style="margin-top:-10px" frameborder="0"
webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>
当触发第1帧的click事件时,我需要路由到另一个组件。(我已经在根组件的路由文件中指定了)。
现在在i frame应用程序(mvc应用程序),我触发了一个点击功能
parrent.showme()
并在angular 2应用的根目录下添加index.js(通过index.html链接)
index.js
function showme()
{
alert('function called');
FooModule.FooInstance.onSelectid();
}
现在我可以在angular 2的应用页面上通过点击I帧应用来显示alert了。
目标是修改showme()的功能,以改变angular 2应用的路由。
我该怎么做?
我试了好几种方法来解决这个问题,可惜都没用。
为框架添加id,然后在iframe元素上使用contentWindow.document.body.onclick
<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']);
}
}
相关文章:
- 如何使失败的路由解析承诺加载不同的模板URL
- 在angularjs中动态路由url路径
- API的快速路由-当您有子资源时的URL处理程序
- 直接使用 React Router + React + Flux 路由到 URL
- JavaScript:从具有使用 # 符号的路由的 URL 获取查询字符串
- Angular-使字符串对URL安全-路由是否正确
- UI路由器:直接使用url访问路由
- 如何在CanJS中更改路由url
- 根据路由URL设置select的值
- AngularJS路由:URL中不必要的参数
- 如何找出哪个 JS 文件正在重新路由 URL
- 节点 JS 路由 URL 冲突
- 在应用程序启动时生成路由 URL 列表,并插入到 MVC 中的 javascript 文件中
- Ember.js路由:url中的动态段错误
- 重新路由url | Nodejs | Express
- 如何在AngularJS的路由url中传递参数
- EMBER直接路由URL访问不加载数据
- 如何在角度应用程序中访问非路由 URL 参数
- AngularJS路由url删除这个&;#!&;
- 如何从AngularJS的路由/ url中移除标签