3

There was a same question like this but the answers didn't satisfy me. I'm designing a view for my django app and I need to force client to enable his browsers JavaScript but I have no idea how to do that. Should I check cookies for testing JavaScript enabled or there is an internal django function for that or something else? Please I want to design with JavaScript and don't tell me build non JavaScript pages!

hamidfzm
  • 4,595
  • 8
  • 48
  • 80
  • http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is-disabled http://stackoverflow.com/questions/4454551/check-if-javascript-is-enabled-with-php these might answer your questions, I guess django does not provied a way to test it, since its also server side – xhallix Feb 06 '14 at 11:50
  • @ChristophHa But as I said it's a django app not php or ... . I need answers related to django. – hamidfzm Feb 06 '14 at 11:51
  • 1
    Django is a server side framework so you can't check from there. You need to do a test on the client side and report back to the server: changing a hidden input or something. Also, you can't force a user to enable their javascript - it would defeat the purpose of disabling it – Timmy O'Mahony Feb 06 '14 at 11:53
  • @TimmyO'Mahony OK but php has this capability to check so I thought maybe django is the same. And django is serving views so it must be some thing for that like checking for cookies! – hamidfzm Feb 06 '14 at 11:56
  • How does PHP check if javascript is enabled? – Timmy O'Mahony Feb 06 '14 at 11:57
  • @TimmyO'Mahony look at Christoph Ha second link. – hamidfzm Feb 06 '14 at 12:00
  • 3
    I have, and like I said, it says that you can't check for javascript from PHP. You need to do some sort of test via ajax or something similar. This is the same as Django. Neither Django nor PHP have a **built-in** method for checking for javascript – Timmy O'Mahony Feb 06 '14 at 12:01
  • @TimmyO'Mahony Can you show me some code in answer for doing what you said. I will be really grateful. – hamidfzm Feb 06 '14 at 12:04
  • What exactly are you trying to do? There is no way for force the user to enable javascript so the best you can do is to let them see a message asking them to enable it – Timmy O'Mahony Feb 06 '14 at 12:10
  • 1
    @TimmyO'Mahony I want to check whether it is enabled show a view whether not show a different view. – hamidfzm Feb 06 '14 at 12:27
  • 1
    @HamidFzM, Christoph's first link contains a very reasonable description of how to do this with javascript, as well as confirming what Timmy has told you - namely that there is no reliable way to do this server-side. – cms_mgr Feb 06 '14 at 17:02

2 Answers2

3

From a comment:

I want to check whether it is enabled show a view whether not show a different view.

This is your real question, and if you had started with this (instead of assuming you had to check from Django) there wouldn't have been an argument in the comments.

How to redirect javascript-enabled browsers to a different view

Put this in the header of your non-javascript page:

<script type='text/javascript'>
   window.location = "/javascript_view.html";
</script>

Nothing Python, Django, or cookie-related is necessary.

Izkata
  • 8,961
  • 2
  • 40
  • 50
  • Thanks I think I have good idea I can put a text in my template telling client to enable the JavaScript and with JavaScript enabled I can change innerHtml of that part and delete the text! – hamidfzm Feb 07 '14 at 01:27
1

After this ends up in a long discussion (see comments) just read this post, this should answer your question , since you asked to have some example specifically for django

Django check if JavaScript is on

Community
  • 1
  • 1
xhallix
  • 2,919
  • 5
  • 37
  • 55