Honestly, it depends on the exploit being used. If it's a browser based exploit, more often than not, an attacker isn't going to care about the User-Agent that you're sending, as long as there is an exploit for that browser. There are certain exploits in Metasploit that don't send payloads whenever they detect an incompatible browser (via the UserAgent), but an attacker can easily modify those scripts to blindly attack.
If you're looking to protect yourself from drive-by attacks, or when you click on a malicious link by mistake, I would recommend installing NoScript to prevent script execution except on trusted websites. Even extensions such as AdBlock help - a lot of exploits are delivered via ad-delivery networks, and AdBlock will block some of these as well.
Rory mentions using Beef and Java applets - while the latest update of Java does provide protection against unsigned applets, letting Java execute on your browser is the surest way of getting exploited. I've used this during penetration tests far too many times, and I've seen it in action as a payload used by attackers too.
The point is that there is no way to really "obfuscate" yourself on the Internet completely. You can do certain things that make you safer, but at the end of the day, the best way to protect yourself from such attacks is by simply being careful of what links you click on, and remembering that the Internet is a dangerous place.