Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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%'
}).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();
});
}
});
@shz

This comment has been minimized.

Copy link

commented Apr 15, 2011

FYI, you can collapse those css declarations by just passing an object rather than chaining calls. Example:

foo.css({
    top: 0,
    padding: 5,
    'margin-left': '-45%'
})
@defrex

This comment has been minimized.

Copy link
Owner Author

commented Apr 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.