There are already some great answers here, and I realize I'm late to the party.
However, one thing that I didn't see mentioned and that I've found helps prevent fixed fares most times is to simply get into the backseat of the taxi before telling the driver where you're headed. Standing outside and asking if he will take you to wherever you're going is basically just asking for a fixed fare.
And as already mentioned, if they still refuse to turn on the meter just get out and get the next one. Like most things - don't act like a tourist (i.e. standing outside with a map in your hand and asking him through the rolled down window if he can take you to Khao San Road :) and your success rate will greatly improve!
Another great tip is have the name of the place you're going ready in Thai script in your phone. Just search for the place in your map app or Google it. Even if there is no name in Thai the driver can hopefully read the address even if it's in english.
To more specifically answer your questions:
Does it make sense to prebook your taxi using online websites or it will be as good to get one at the airport?
Well, if you use Grab you'll get a normal taxi anyway. Almost every time I've used it the driver has called me up to ask where I am, instead of just looking at the location. This gets really annoying if their english is non existent, and I frankly find it easier to just get the same taxi on the street (and save the booking fee).
If you want the least hassle and the best experience, I guess you could try Uber. The cars and drivers are usually in a whole other class than the regular taxis, but my personal experience in Bangkok is that you might have to wait 20 minutes or so for the car to show up, and the price might be slightly higher than a metered taxi.
However, at both airports there are pre booked taxis available. You go up to a counter, tell the person there where you're going, and they make sure to instruct your driver about your destination. Usually completely hassle free. There is a fee for this service (don't remember how much, but not much). The driver might ask you if you want to take the tollway or not - if you want to beat the traffic it's a good option, but make sure you have cash for the tolls since you're expected to pay for them directly, not when you arrive at the destination.
How to tell scam taxis from legitimate ones in Bangkok?
Not sure what you mean by scam taxis, but I suspect you might have heard stories of naive tourists who paid ripoff amounts for a ride with a tuk tuk. These things are generally tourist traps if you don't know what you're doing, especially in Bangkok.