OK, yes it could be done that way. But why would you? Using your method assumes that JavaScript is enabled in the browser. My WEB sites record enough browsers without JS activated to make it worth our while to NOT use JS. Only place we use it is for some form validation, it makes things faster on the client side, but we always have ful validation in our Perl scripts to do two things:
Make sure our forms and JS are not tampered with
Validate where client has no JS.
By using your method you would exclude a fair percentage of browsers.
jdtoronto