learner
learner

Reputation: 21

Detecting tab close event using java-script or j query and making a user authed google api call

I am implementing a profile update where user can view and edit his profile info and add more images to profile. But if someone has uploaded some images (which I m storing in google blobstore) and then closes windows or reloads it then I want to delete the images uploaded to blobstore.

I have already written function which is deleting fresh images uploaded whenever is click on specific button. But when I call the same function on

window.onbeforeunload = function(){

};

Its not working. Please help what I am doing wrong.

Upvotes: 0

Views: 29

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39824

I wouldn't rely on the client to perform cleanup: no matter how complex your cleanup logic is you'll never be able to cover all cases. For example the browser or the computer may crash, your client-side cleanup code wouldn't run.

Instead I'd focus on the (single) positive action (like an "Apply Changes" button click) to use the uploaded image and would perform the cleanup for all other cases (whatever their reason may be) with a single cron job deleting images not applied after a certain grace interval following their upload.

Apart from the simplicity this approach would also allow your app (if you want, if course) to be even friendlier with your users, for example one could still apply an uploaded image even if they visited some other page or their browser crashed after they uploaded the image.

Upvotes: 1

Related Questions