I need to trigger some event from the base window to a popup window when a user tries to open the same popup window again, which is a gear icon dropdown. What are the different ways I can approach this use case? I tried using a service but since the base window and popup window are different angular applications, it's creating a different instance of the service.
import { Injectable } from "@angular/core";
import { Subject } from "rxjs";
@Injectable()
export class ServiceMessage{
subscribers: any = [];
private subject = new Subject<any>();
sub = this.subject.asObservable();
a: any = [];
constructor() {}
nextSub(data: any) {
this.subject.next(data)
}
}
Solutions:
Get the flag from local storage
Window.postMessage()
to communicate. Thewindow.postMessage()
method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.More on
window.postMessage()
here https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage