Detect: JavaScript Enabled or Disabled
I am looking for a way to test if the user has disabled javascript on their browser. I am building a JS/CSS menu which I would like to provide an backup for should they have JS turned off.
Back to top |
|||||
Just use <noscript>.....</noscript> to have the content you want if javascript is turned off. There's some validation issues with <noscript>, it can't be in a containing block level div, p or a few others.
Or you can have the default behavior overridden by javascript, that's I think the best choice, for example have a CSS library file for the active JS triggered component triggered by something like this: :: Code :: <head>
<title>test page</title> <link rel="stylesheet" href="/css/default.css" type="text/css"> <script type="text/javascript">document.write('<link rel="stylesheet" href="/css/menu-js.css" type="text/css">');</script> </head> // you have to escape the document.write <link... html a bit to avoid it being parsed by the browser. It's hard to say more without seeing a code sample of what you're doing. Oh, and welcome to the forums. Back to top |
|||||
you can check that javascript is enabled or not
A script can be detected by using <noscript></noscript> tag
If a message placed in noscript tag displayed this mean javascript is no enabled code <script type="text/javascript"> <!-- document.write("Hello World!") //--> </script> <noscript>Your browser does not support JavaScript!</noscript> if enabled print helloworld else Your browser does not support JavaScript![/code] Back to top |
|||||
All times are GMT - 8 Hours
|