Skip to content

Instantly share code, notes, and snippets.

@ashchristopher
Forked from defrex/jquery.500frame.js
Created August 12, 2011 19:35
Show Gist options
  • Save ashchristopher/1142807 to your computer and use it in GitHub Desktop.
Save ashchristopher/1142807 to your computer and use it in GitHub Desktop.
pop-up any 500s in an iframe using jQuery. Especially useful for Django errors.
$(document).bind('ajaxError', function(e, jqXHR){
if (jqXHR.status == 500){
var erframe = document.createElement('iframe');
$('body').append(erframe);
$(erframe).css({
'position': 'absolute',
'top': '5%', 'left': '50%',
'width': '90%', 'height': '90%',
'marginLeft': '-45%',
'z-index' : '9999999'
}).attr('id', 'errorframe');
var doc = erframe.document;
if (erframe.contentDocument)// for moz
doc = erframe.contentDocument;
doc.open();
doc.writeln(jqXHR.responseText);
doc.close();
var close = $('<a href="#" id="errorclose">X</a>');
$('body').append(close);
close.css({
'position': 'absolute',
'top': '0', 'right': '0',
'padding': '5px'
}).click(function(e){
$('#errorframe').remove();
close.remove();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment