I use the following frontend code to export a .csv document.
.csv
HTML
In jQuery simply use :
$(window).off('beforeunload');