: How to have html display a link, but open a javascipt function instead? 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
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
More posts by @Bethany197
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.