Skip to content

Instantly share code, notes, and snippets.

@defrex
Created April 11, 2011 19:06
Show Gist options
  • Select an option

  • Save defrex/914083 to your computer and use it in GitHub Desktop.

Select an option

Save defrex/914083 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%'
}).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

shz commented Apr 15, 2011

Copy link
Copy Markdown

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

defrex commented Apr 15, 2011 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment