Search code examples
javascriptdownloadhyperlinkgreasemonkeyhref

How to distinguish a link whether it will trigger file downloading or jumping into anywhere else, such as a new URL


I get an idea writing a GreaseMonkey user JavaScript that can detect which is the exactly real download link rather than an advertisement link or something else.

Actually, I find that some real download link is linked to .php. It's tough to detect it I think.

How could I do that, any ideas?


Solution

  • The only reliable way to do it is to follow the link and check what Content-type you will find in the header of the response. If you can, try to send a HEAD request instead of a GET. That will give you the information you need without actually starting the download.