10 changed files with 73 additions and 3 deletions
@ -0,0 +1,2 @@
|
||||
<button (click)="xxx()">向子页面发送信息</button> |
||||
<iframe id="iframe" src="http://192.168.1.86:25647/login" frameborder="0" width="100%" height="100%"></iframe> |
@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { IframeComponent } from './iframe.component'; |
||||
|
||||
describe('IframeComponent', () => { |
||||
let component: IframeComponent; |
||||
let fixture: ComponentFixture<IframeComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ IframeComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(IframeComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,27 @@
|
||||
import { Component, OnInit } from '@angular/core'; |
||||
import { Renderer2} from '@angular/core'; |
||||
@Component({ |
||||
selector: 'app-iframe', |
||||
templateUrl: './iframe.component.html', |
||||
styleUrls: ['./iframe.component.scss'] |
||||
}) |
||||
export class IframeComponent implements OnInit { |
||||
|
||||
constructor( private render2: Renderer2) { } |
||||
|
||||
ngOnInit(): void { |
||||
} |
||||
xxx(){ |
||||
this.handleToIframe() |
||||
} |
||||
handleToIframe() { |
||||
const child = this.render2.selectRootElement("#iframe"); |
||||
console.log(child); |
||||
let data = { |
||||
from: 'parent page', |
||||
code: 200, |
||||
data: '来自父页面的数据!!!' |
||||
}; |
||||
child.contentWindow.postMessage(data, '*'); |
||||
} |
||||
} |
After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in new issue