/    Sign up×
Community /Pin to ProfileBookmark

Help with window.onbeforeunload()

Hi, my requirement is upon refreshing or closing the browser tab, there should be my custom alert instead of browser alert. I have to get this work done in typescript so I am returning the $event.returnValue = false on beforeunload event which will stop my browser from closing or refreshing but at the same time I want my custom pop-up to be shown instead of browser pop-up.

` @HostListener(“window:beforeunload”, [“$event”])
beforeUnload($event: Event) {
//loading my custom pop up
$event.returnValue =false;
}`

My Custom Pop-up loads but loads after I cancel the browser popup-
[upl-image-preview url=https://www.webdeveloper.com/assets/files/2020-05-18/1589786849-436737-browserpopup.png]

How can I achieve this? What am I doing wrong? Please help.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @fuzzyprototype spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...