Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Save link as" Event

Suppose on a web page, there's a link that lets the user download the current state of the application in some file format like so:

<a href="example.com/download/url" id="download-link">Download</a>

I can easily listen to the click event and make sure that the most recent state is pushed to the server before the download request is made, like so:

$('#download-link').on('click', function(event) {
   event.preventDefault();
   pushStateToServer().done(function(){
     window.location.href = event.target.href;
   });
});

This, however, does not work if the user right clicks the link and selects "Save link as".

Is there any way for me to catch this event?

like image 773
Georg Avatar asked Oct 24 '25 14:10

Georg


1 Answers

No, I'm pretty sure there is no way you can achieve this.

The only thing you can catch is contextmenu which is when you right-click on the link, but there isn't a way to find out what link in the context menu was clicked.

This is as close as you're gonna get.

$('#download-link').on('contextmenu', function(event) { ... });
like image 80
iConnor Avatar answered Oct 26 '25 05:10

iConnor