Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an html page, and I need a link to show that the user would be going to 'example.html', when really, the link goes to 'javascipt:ajaxLoad(example.html);'.

EDIT: I went over to stackexchange, and their solution worked. The html would go from this: Example to this: Example

The solution, is if javascript is enabled, the 'return false;' will cancel going to the link on the page, and load the javascript. If not, then it will go to the page in the href

share|improve this question

Have the HTML with a working link in it that leads to the content you want to show. Then use JavaScript to stop the browser from taking them to that page and then use Ajax to show the content to them in their current page.

This is known as progressive enhancement and allows everyone to see the content whether they have JavaScript enabled or not. How to write this code will vary depending on what JavaScript framework you use (Prototype, jQuery, MooTools, etc). But the psuedocode would look something like this:

  • on DOM load attach an event monitor to that link
  • when that link is clicked stop the default event (the browser loads the new page)
  • Make your ajax call to get the new content
  • Replace the existing content with the new content

If you want code help you will need to go to StackOverflow as that is where coding questions are handled. This question in its current form would probably be closed there since it doesn't show any effort to write some code. So I suggest starting to write your own code and then if you have trouble ask for help there showing whatever code you have so far.

share|improve this answer
A more specific term than Progressive Enhancement (related to the question) might be Unobtrusive JavaScript – feeela Jul 21 '11 at 18:44
Thanks. I will head over there. – Austin Witherspoon Jul 21 '11 at 18:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.