There are (at least) two ways you could approach this (depending on how it fits in with your Ajax code):
- Handle all clicks on the page with a common function that cancels the default click navigation and then subsitutes its own to load in iframe, new window, etc.
- Process all links on the page when the page loads, setting the
target attribute as appropriate.
So the first way:
$(document).on("click", "a", function(e) {
// stop default navigation
e.preventDefault();
// 'this' is the particular 'a' that was clicked
var url = this.href;
// process url somehow as desired to decide whether to open it
// in new window, or iframe or to replace current page
});
Noting that the .on() method applies from jQuery version >= 1.7, so for older jQuery use the .delegate() method or for really old jQuery use the .live() method.
The second way (assumes links all exist when page is first loaded):
$(document).ready(function() {
$("a").each(function() {
var url = this.href;
// process url somehow and set the target attribute as appropriate
// e.g. for a new window
this.target = "_blank";
// or for an iframe
this.target = "nameofiframe"
// etc.
});
});