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?
There is an easy work around for this, by simply returning true or false within a inline JavaScript event. If JavaScript is disabled, the browser will proceed to load the href target. While if JavaScript is enabled, the onclick event will return false; letting the browser know not to load the href target link, instead, we can do some AJAX, or DOM (in this case) HTML manipulation.
For instance,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <script language="javascript"> function example () { // Simple DOM JS document.getElementById('alter').innerHTML = 'Ajax like event triggered.'; document.getElementById('alter').innerHTML += '<br />'; document.getElementById('alter').innerHTML += '<img src="screenshot.png" title="Screenshot" alt="Screenshot" />'; // return false; so the browser knows not to continue, if JavaScript is enabled. return false; } </script> <p id="alter"></p> <a href="/screenshot.html" onclick="return example();">link</a> |