Question

I have a large, dynamically generated, single page website that heavily relies on javascript. I want to have a fallback for people without javascript.

Each version must have different php code, so basically I need an entirely different index page. I dont want to wrap EVERYTHING in javascript, and EVERYTHING ELSE in tags. Unless there is an easy way of doing that.

What is the best way to load one page or the other depending on whether javascript is enabled or not?

Was it helpful?

Solution

First, to directly answer your question, you could redirect the user away from the first index page if JavaScript is enabled using location.href. That is, if the user does not have JavaScript enabled, they will remain on page one. Else they will be redirected to the JavaScript version.

But the way I would generally go about doing this is to first make sure the website works without JavaScript; then add in the extra code for JavaScript after that plain version works.

<a href="foo.php" onclick="return foo();">Foo</a>

Here, if JS is not enabled, they will go to foo.php. Else, you can have the function foo do something and return false, thus keeping them on the page. The same thing can be done for forms.

OTHER TIPS

Use the noscript tag to provide the user with a way to the non-javascript page..

example: code at http://jsfiddle.net/xdYNE/ running (when JS off) at http://jsfiddle.net/xdYNE/show/

(hint: see it with JS disabled to understand..)

Seems like putting a PHP redirect inside noscript tags would be the simplest way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top