See this article for working options
Important updates: this code won't reliably work anymore. If you don't need smartcard support, use the experimental web crypto API. If you need smartcard support, you'd need an extra plugin, e.g. this one
Digitally sign content by using only javascript. Smart cards are supported. Self-signed certificates may or may not work.
Supported browsers: Internet Explorer (CAPICOM), Firefox (window.crypto)
Chrome and Safari will implement this whenever the DOMCrypt standard is defined by W3C.
You can read this relevant blogpost.