Is there a way to prompt the users for activating JavaScript with server-side event handler in case JavaScript is turned off on their PCs, where they shall be asked to press a button (submit a form, I mean) in a popup window or designated DIV in order to activate the JavaScript?
-
Are you asking for code that can force a user's browser to enable javascript? – thatidiotguy Sep 14 '12 at 20:32
-
Yes, the code itself shall offer an option to enable javascript. Thanks, – Klanto Aguntuk Sep 14 '12 at 20:57
-
1You can't force a browser to enable javascript. Without javascript enabled it is basically a text reader. – scrappedcola Sep 14 '12 at 21:03
-
As far as I remember I enabled javascript in my browser through a website by pressing a button in a prompt window or div about 14 years back. I want to implement the same application for myself now. – Klanto Aguntuk Sep 14 '12 at 21:07
-
keywords in your comment "14 years back" security has gotten tighter since then. It is considered bad form to force a browser to do anything like that without user interaction. All you can do right now is test for js and inform them that they need to turn it on. – scrappedcola Sep 18 '12 at 19:18
3 Answers
No, there's no way to do this. However, you can provider a <noscript>
tag that would explain users how to turn JS on.
For example:
<script>alert('hi');</script>
<noscript>Please enable JS by opening preferences panel in your browser</noscript>
You may want to use server-side browser sniffing to provide most relevant guidance to user (by telling them how to do that in a browser they are currently using).

- 15,630
- 2
- 34
- 35
-
I've already went through the similar articles many times. it's not what I'm looking for. Many thanks. – Klanto Aguntuk Sep 14 '12 at 20:41
-
You could set up a div with a particular id that is hidden when the page loads. Then when the page loads you hide the div. If they have js the div will hide. IF they have it turned off (not really a likely eventuality here and now but whatever) then they see the div.
<div id="hasJsOn">Please turn on javascript for full enjoyment of this page.</div>
<script>
document.getElementById("hasJsOn").style.display = "none";
</script>

- 10,423
- 1
- 32
- 43
-
Many many times, I read about this solution. That's not what I'm after. Many thanks. – Klanto Aguntuk Sep 14 '12 at 20:42
-
You haven't the answer, that doesn't mean that my question is bad. Hahaaa. – Klanto Aguntuk Sep 14 '12 at 20:44
You can detect if JS is enabled on the end user's machine and you can pass that information to the server on the next page they visit by using Javascript to add a URI Component
to forms/links.
Example (Untested "on-the-fly" code):
<form action="postit.php">
<p>
<input type="hidden" id="js_detector" value="0">
</p>
</form>
<script>
document.getElementById("js_detector").value = 1;
</script>

- 23,369
- 6
- 54
- 74
-
The action should take place as soon as the visitors lunch the respective page in their browsers. The prompt window should appear at the moment the serverside code detects the visitors' browsers have javascript disabled. Many thanks, – Klanto Aguntuk Sep 14 '12 at 20:54
-