if your question is "by code", this needs to be done using JS... There are several implementation possible (I looked at it a few month back) and none of them is foolproof (supported or not depending on the browser, version of this, of that...)
So it's not trivial... and from the top of my head, there were several thread quite recently n the french pcsoft forum regarind just that, with some examples of code