Updatd code to call my custom javascript function when the user clicks export so this can run in the background instead of in memory