tags:

views:

85

answers:

6

Hello,

My site heavily depends upon javascript and if i turn off javascript my website looks real ugly. I want to force user and show him notification to turn on javascript else prompt him that site can't be viewed. What do i do to achieve this?

+2  A: 

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.

CharlesLeaf
Hi CharlesLeaf, i am using JQuery and its plugins and it won't work if user disables javascript. What do i do?
Ankit Rathod
yes it will, maybe you should read it again.
CharlesLeaf
@jaywon: *What* won't work?
Boldewyn
Nitesh, my answer and the <noscript> solution are the only 2 things you can do. So read about both of them, and just try them out.
CharlesLeaf
Also, remember that not everybody has Javascript disabled by choice - people at the office usually don't have an option, and in some cases firewalls/virus scanners like to block things.
CharlesLeaf
@CharlesLeaf - you are right, my apologies. I still don't think it's a particulary "good" answer, but it would work i suppose. That's what the noscript tag is essentially for without all the extra work
jaywon
@CharlesLeaf, not to mention screen readers for visually impaired users.
ereOn
I think ereOn is strong supporter of not to use javascript :p. But i am using world's most popular javascript library, JQuery and my sit will work only if javascript is enabled due to lightbox and other plugins. I wish i could rate him negative if he had answered :). Unnecessarily my question has been downvoted.
Ankit Rathod
@jaywon @ereOn I know, but you could also combine both techniques. What I ment was more that with unobtrusive javascript you usually load a separate "js only" stylesheet that hides/shows things that you don't need if JavaScript is working. I guess in this case <noscript> IS better yes. @Nitesh well, you have plenty of options so I'm sure you'll figure something out. And when you have time read http://www.alistapart.com/articles/behavioralseparation
CharlesLeaf
+5  A: 

Have 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.

jaywon
...and ask the user nicely to re-enable Javascript. No other option.
SF.
@SF, haha was editing my post as you added that to say pretty much the same thing
jaywon
I'm pretty sure visually impaired users will be pleased to learn that "this website was not designed for blind people ! Just go away !"
ereOn
@ereOn - from the post it pretty much sounds like that's exactly how it was designed. I never said building a heavily JS dependent site was a good idea, I just answered the question.
jaywon
@jaywon: My apologies. I misread the "best viewed" part of the answer.
ereOn
+1  A: 

I watched an interesting talk by John Resig (The creator of JQuery) and he even mentions in his video, do not rely on Javascript.

PieterG
+1. That's a sane advice indeed. A good website must remain usable without Javascript. That doesn't prevent Javascript to improve usability, but one **must not** rely on it.
ereOn
A good website does what it's client/clients expect from it. What ever moral issues you have with it does not apply. There are sites that I work on that would be impossible to use without javascript. But, our environment has these base builds that fits that requirement and always will. So if someone does not have javascript enabled, his boss will be comming to see him. It's a nice to have, even a good practice, but only where it's possible and worth the effort.
A: 

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.

ivans
A: 

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.

cHao
+1  A: 
<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