javascript - Disable Browser onUnload on certain links? -
i working on web hosting panel has dns records manager. have use lot of javascript make perform desktop application.
i wanted show custom dialog window when a browser runs beforeunload
after research have discovered stuck using browsers default dialog window.
so javascript code below that, problem need make sure not fired off on link clicks.
i hoping able maintain array of css class names, , if link clicked in array not show onunload event.
i'm sure easy javascript developer. show me how this?
//sample class array safelinks = ['test', 'test2', 'test3', 'test4', 'test5']; // onunload event $(window).on('beforeunload', function(){ return 'are sure want leave?'; });
you remove event handler when they're clicked:
var safelinks = ['.test', '.test2', '.test3', '.test4', '.test5']; function promptbeforeclose() { return 'are sure want leave?'; } $(window).on('beforeunload', promptbeforeclose); $(document).on('click', safelinks.join(', '), function(e) { $(window).off('beforeunload', promptbeforeclose); });
also, if these safe links have common ancestor, use instead of document
delegation parent or people complain. ;)
Comments
Post a Comment