I'm not the only one who has been plagued lately with seemingly well-meaning sites suddenly warning me that some piece of software on my Mac is out-of-date and that I need to update 'whatever' (often Flash). Then, my browser just goes ahead and accepts their download (probably malware) onto my computer and I can't stop it. How can we stop Safari from downloading files without asking first? It seems that these infected sites 'push' the downloads on you, and Safari does nothing to stop it. BTW I'm using Sierra (10.12.6) and Safari 12.1.2. I hear that this happens with other browsers as well. Open "Safe Files" after downloading checkbox is not checked. Any ideas?
The real solution is upgrading to Safari 13, but there does exist a solution on Safari 12 and earlier.
Open Safari Preferences, choose the General tab, and for the download location choose ‘ask for each download’.
With this option select, Safari will prompt for a file name and a location to save the file, which you can cancel so the download doesn't take place.
By researching over a half dozen sites regarding browsers, I've been able to determine that the only browsers one should use for an older OS such as Sierra are ones that are still updated regularly, otherwise they are not secure. With Firefox, and perhaps others, you get a window naming the item and requiring the user's approval before downloading, which would solve my immediate complaint.
I was not able to find the offending website again, so I don't yet know for a fact that this can stop a deliberate attempt to dump the file on the user.
However, Todd's answer was fundamentally correct; if one wanted to rely on Safari as their primary browser, then that would be one of many reasons why they would be best advised to upgrade to Catalina. I would add that if, for whatever reason, one were not yet able or prepared to upgrade the OS, then a different browser should be used.