Solved

Redirecting to another page if javascript is disabled

Posted on 2009-05-16
5
255 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:sandhya01
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
pedro_sland earned 250 total points
ID: 24402470
A html page cannot force a user to use javascript. It would be better to design a page so that users without javascript can use it as well as users with. If this is really necessary then use something like this in your <head>:

<noscript>

  <meta http-equiv="refresh" content="0;URL=http://yoursite.com/nojs.php">

</noscript> 

Open in new window

0
 

Author Comment

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

Thanks
0
 
LVL 2

Expert Comment

by:pedro_sland
ID: 24439603
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

0
 

Author Comment

by:sandhya01
ID: 24493376
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

0
 
LVL 2

Expert Comment

by:pedro_sland
ID: 24501482
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now