My site heavily depends upon Javascript and if I turn it off my website looks real ugly.
I want to force the user to use Javascript by show him a notification to turn it on, else prompt him that site can't be viewed.
What do I do to achieve this?
My site heavily depends upon Javascript and if I turn it off my website looks real ugly.
I want to force the user to use Javascript by show him a notification to turn it on, else prompt him that site can't be viewed.
What do I do to achieve this?
Share Improve this question edited Aug 31, 2016 at 21:58 nbro 15.8k34 gold badges119 silver badges213 bronze badges asked May 26, 2010 at 9:36 TCMTCM 16.9k46 gold badges158 silver badges255 bronze badges 12- 2 Seconding ereOn: If you can't make your site working without JS, simply tell the user, that it's necessary because of (insert understandable reason here). Don't force her to anything. – Boldewyn Commented May 26, 2010 at 9:41
- I am curious why this question has been pushed down to -3. Surely people are not dropping this question because of some moral ethics code? – guyumu Commented May 26, 2010 at 9:49
- Hi guyumu, that's what i am thinking why ereOn and some other commentators downvoted my question! May be they are against using javascript or may be they can't digest the success that JQuery has been getting these days. I wish i could also downvote him 10 times more than what i am downvoted :) – TCM Commented May 26, 2010 at 9:53
- 3 @guyumu: Actually, I didn't downvote. But forcing users to enable Javascript is a bad practice. What if someone forces you to use Windows 95 because he is too lazy to make a compatible software ? The same logic applies here. – ereOn Commented May 26, 2010 at 9:53
- 1 @ereOn - that's the second time you've slammed me for something i didn't say. I said I got downvoted, not that YOU did it. My point to him was not to take the comments/voting so seriously, and my advice to you would be the same. – jaywon Commented May 26, 2010 at 10:15
6 Answers
Reset to default 6Have a look here:
noscript tag
All you can do is test that javascript is turned on or not, and show a notification that the site is best viewed with javascript turned on.
<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>
Your browser does not support JavaScript!
</noscript>
Also, feel free to google 'html script tag' and see http://www.w3schools.com/tags/tag_noscript.asp
First off, be warned that forcing the user to do anything is usually considered quite rude. Lots of people keep javascript either disabled entirely or severely restricted precisely because some twerp wanted to use it to force them to do something or look at something.
With that said, you can include some text in <noscript></noscript>
tags. That text will only show if the browser doesn't have javascript, or has it disabled.
For your question:
By default show the notification, and with JS + some sort of document/DOM Ready event just remove the notification. Try not to do this on window/onload because then you'll see the notification until ALL resources of that page have been loaded, which takes longer than dom ready. That way, everybody who doesn't have JS will see the message.
But ideally you'd just want to have a website that works with, or without javascript. Maybe unobtrusive javascript is a nice search term for you.
I watched an interesting talk by John Resig (The creator of JQuery) and he even mentions in his video, do not rely on Javascript.
You create a landing page that uses a <noscript>
tag to inform the user that your web site doesn't work without Javascript. Then you go and pray $DEITY for forgiveness because you added to the general mire pool that is the web.