4

I want to check if Javascript enabled or not. If its enabled then it show the rest of code but if it's disabled it will redirect to google.com

Now, how to do that? I'm trying to write this code:

<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>Your browser does not support JavaScript!
<p>JS must be enabled</p>
<META HTTP-EQUIV=Refresh CONTENT="3; URL='www.google.com'">
</noscript>
<p>this code must be hidden when JS is disabled</p>

but the result is:

Your browser does not support JavaScript!
JS must be enabled
this code must be hidden when JS is disabled

and what I want to is the code outside the noscript won't run if there's no JS enabled so, at the example it would like this:

Your browser does not support JavaScript!
JS must be enabled
(go to google)

Info: I'm using PHP

3 Answers 3

3

I think your code is correct please change

<META HTTP-EQUIV=Refresh CONTENT="3; URL='www.google.com'">
this to
<META HTTP-EQUIV=Refresh CONTENT="3; URL='http://www.google.com'">

use http://

and for content hiding use a class for body and set its property to display none, and use a jquery function to add display block to show the content, the jquery function only works if javascript is enabled. so the content is disabled for javascript disabled mode.

eg.,

<style>
.test
{
  display:none;
}
</style>
<script>
$(document).ready(function(){
    $(".test").show();
});
</script>
<p class="test">The section should hidden for javascript disabled mode</p>
Sign up to request clarification or add additional context in comments.

1 Comment

do not forget to include jquery library <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/…>
0

You can do something like this:

<noscript>Your browser does not support JavaScript!
<p>JS must be enabled</p>
<META HTTP-EQUIV=Refresh CONTENT="3; URL='http://www.google.com'"> <!- Note: remind to put the http:// prefix -->
</noscript>
<body style="display:none">
--- YOUR CONTENT HERE ---
--- USE JAVASCRIPT TO MAKE THE BODY VISIBLE ---
</body>

Comments

0

It is easier (and standards-compliant) to use JavaScript to redirect to the page you want. If JavaScript is not enabled it will simply load the <noscript> info on the page since JavaScript could not redirect.

1 Comment

Thanks for respond right now, what I want really do is creating a form outside noscript, so user could fill the form. Before fill the form, I create a prompt to fill a keyword/password then they could fill it. But if the JS is disabled, the form not displayed and redirect it to google.com so my question is about how to hide the form if JS is disabled.. sorry for my bad english/explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.