A few ways (without giving detailed JavaScript code):
When a user first starts a session on your web site,
give a small referrer page that takes one to a nan-JavaScript
site, but have a JavaScript event for on-load that overrides it
Use JavaScript to send a cookie that says "JavaScript=on" (I've
seen some web sites do this; I think Netscape's home site used to do this.)