Link to home
Start Free TrialLog in
Avatar of sandhya01
sandhya01

asked on

Redirecting to another page if javascript is disabled

Hi Experts,
I want to include a logic in my index.php page that if the Javascript is disabled on the users system, it shoud automatically redirect the users to another page.
Only if the javascript is enabled shoudl the user be able to access that page.

Also, is it possible to automatically enable javascript on the users browser when they try to access my index.php page?

Please help
Thanks
ASKER CERTIFIED SOLUTION
Avatar of pedro_sland
pedro_sland
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sandhya01
sandhya01

ASKER

Hi pedro_sland,
It is fine to use meta http refresh, in your html page?
Please let me know.

Thanks
Its not very good but I think its the only way to do what you ask.

I recommend this method though. Progressive Enhancement with Javascript is a good article to explain what I mean by a page for users with and without javascript. If you need help with replacing inline event handlers and browsers difficulties, try the Prototype library or jQuery. I use jQuery for my js. There are also a great list of plugins to do almost everything you could want!

If you wanted to redirect someone who does have javascript to another page, then use something like:
<script type="text/javascript">
  window.location.href = 'http://www.yoursite.com/withjs.php';
</script>
 
If you wanted to show a message asking a user to enable javascript to get the most from your site:
 
<noscript>
  <p>Please enable Javascript in your browser to get the best from this site. <a href="why_use_javascript.php">What Javascript will give me</a></p>
</noscript>

Open in new window

Hi Expert,
Actually I want to implement login mechanism using javascript, So that I should only allow the login page to be visible, if the users have JS turned on. else they should be redirected to another page which has instructions on how to enable JS.

Am I following the right approach.

Thanks

You would be better to use javascript to show the login form (use css to hide it and javascript to show it on page load). If they do not have javascript enabled, show a message instead by surrounding it in <noscript></noscript>. noscript tags are hidden if javascript is enabled.