what I have at the minute works for the first URL test, however, I don't know how to get it to test the second URL, should the first one not exist.
var str = document.title.replace(/ | My Site/i, '');
var title = str.replace(/ /g, '-');
var finish = title.toLowerCase();
var banner = finish.split('-', 1)[0]
var address = "http://example.com/images/" + finish + ".jpg";
var banneraddress = "http://example.com/images/" + banner + "-banner.jpg";
$.ajax({
type: 'HEAD',
url: address,
success: function() {
// Primary URL exists
document.getElementById("TRY").src = address;
},
error: function() {
$.ajax({
type: 'HEAD',
url: banneraddress,
success: function() {
// Secondary URL exists
document.getElementById("TRY").src = banneraddress;
},
error: function() {
// Both failed
null
}
});
}
});
What needs to happen is if the user loads a page and /images/page-title.jpg exists, it will add that src to the the images with the ID "TRY".
If that test fails, if /images/page-banner.jpg exists add that src to the images
And, for now, if neither work do nothing.