Combining Web 2.0 with 1.0

It’s all very nice and dandy to have a website built within 2.0 standards. However, what if the website hasn’t been built for non-JavaScript browsers, or for people with JavaScript disabled?

Since all web 2.0 website’s require JavaScript, whether we are talking about Flash or AJAX. A nice way to resolve this issue is to return true, or false from a function being called via a JavaScript event. This can determine if the client is using a web 2.0 or 1.0 web browser.

An example of this is:

index.html

<script src="test.js" type="text/javascript"></script>
<a onclick="return test();" href="/">a simple test</a>
 
<p id="update">will be updated</p>

test.js

function test () {
document.getElementById('update').innerHTML = 'updated...';
return false;
}

What we have here, is the onclick JavaScript event checking the return type of the test function.

In this case, we are returning false, therefore, we will not follow the hyperlink, but update the content dynamically using JavaScript.

This is very useful when using AJAX, if something goes wrong, we can return true so the browser knows to follow the hyperlink (web 1.0 style). If all goes well, we can return false (web 2.0 style) and update the content dynamically. Then of cause, if JavaScript is disabled, it will follow the hyperlink automatically.

Feedback