Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to prevent onbeforeunload event from triggering when using Internet Explorer

I have a function that is suppose to trigger when user closes their browser and I have put the code in the window.onbeforeunload function.

The thing is every time if I reloads the page in Internet Explorer, the onbeforeunload event will also trigger which is a problem because I only wants it to trigger only when the user closes or navigates away from the current page but not on a page refresh/reload.

Therefore I'm not sure if onbeforeunload is intended to trigger even on a page refresh/reload and if it is intended to, then is there another way to work round it?

like image 265
newName Avatar asked Nov 15 '22 11:11

newName


1 Answers

Since you are relying on javascript as it is, you may want to look into resolving the issue as to why they have to refresh the page. You can use XMLHttprequest to refresh the content for them so that the desired onbeforeunload function is only called when it needs to be.

like image 193
John Avatar answered Dec 06 '22 15:12

John