我有一个html页面(main.html)使用带有window.open("newtab.html")方法的javascript在同一个域中打开一个新选项卡.
在新选项卡中,用户单击按钮执行结束活动的操作.此时我想向开启窗口发送消息.我尝试使用postMessage但是从新标签我不能引用开启者.
从新标签我喜欢的东西,但我"ko"
var w = window.opener;
if (w) {
w.postMessage("hi", "http://10.150.10.43");
} else {
alert("ko");
}
Run Code Online (Sandbox Code Playgroud)
将消息从辅助选项卡/窗口发送到主选项卡(在同一域中)的最佳方法是什么?
非常感谢Luca
我有一个运行良好的 Angular 项目,我正在实施 NG-IDLE 和 KeepAlive,以保持会话新鲜并在 API 会话到期之前注销用户。
我的问题是 ng-idle 也在登录页面上运行,这显然不是必需的,因为当它超时时,它会将人带到登录页面。
因此,我在 app.component.ts 中启动并运行了 ng-idle 和 KeepAlive,但由于我使用的是延迟加载,因此我还有一个 authentication.module.ts 和一个 login.component.ts。
我的根 app.component.ts 中的代码如下:
import { Component } from '@angular/core';
import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';
import { Keepalive } from '@ng-idle/keepalive';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
idleState = 'Not started.';
timedOut = false;
lastPing?: Date = null;
constructor(private idle: Idle, private keepalive: Keepalive) {
// sets an idle timeout of 5 seconds, …Run Code Online (Sandbox Code Playgroud)