(function($) { $.fn.custom404 = function(options) { var defaults = { 404: "/404.html", 403: "/403.html", 500: "/505.html" }; if (options) $.extend(defaults, options); if (!this.selector) var selected = "a"; else var selected = this.selector; $(selected).click(function() { event.preventDefault(); var address = $(this).attr("href"); $.ajax({ url: address, success: function() { window.location.href = address; }, error: function(xhr) { window.location.href = defaults[xhr.status]; } }); }); }; })(jQuery);