Shilpa
Published in : 2022-03-02
I want to open a window containing user authorization form details. I want to do this by checking window location, to do so the event handler not call on every event. I am not able to overwrite event handlers.
Why the event is not triggering? what could be the alternative way to intercept the Authorization form result?
My code:
import { Inject, Injectable } from '@angular/core';// ... other imports will be go here. //@Injectable({ providedIn: 'root'})export class UserWindowService { constructor(@Inject(WINDOW) public window: Window) {} // here WINDOW is imported from InjectionToken<Window> openUserWindow(): void { let windowObj = this.window.open('//localhost:4200/verify', '_blank'); let evntHandler= function() { console.log(windowObj!.location); }; //Below order of events should execute one by one, one after one. windowObj!.onload = evntHandler; windowObj!.addEventListener('load', evntHandler); windowObj!.addEventListener('onload', evntHandler); windowObj!.document.onload = evntHandler; windowObj!.onhashchange = evntHandler; windowObj!.addEventListener('hashchange', evntHandler, false); }}
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Rakshit Date : 2022-03-05
Best answers
34
Best answers
34
When you call “window.open()”, it seems like, your window may be blocked by a popup blocker. Chrome Firefox and other giants in browsers - all are using one common thing, like popup blocker to prevent loading of hundreds of tabs using javascript - malscript functionality.
You should check if the “window” variable exists or not.
when you use exclamation mark, “windowObj!.onload”, you are forcing to open a window.
In such case, window!.addEventListener() might not work (exclamation will fail) if window does not exist.
Shilpa Date : 2022-03-06
Best answers
10
Best answers
10
Yes popup blocker is issue, if I am allowing popup from the top of chrome browser, it works fine! Thanks for sharing knowledge.