Open erikvanoosten opened 10 years ago
A work-around would be to add the following lines (only for HTML with JSON, like Error{"_links":{"self":{"href":"api"}}}
will popup a window with Error
and render remaining JSON):
js/hal/views/resource.js:13
var response = e.jqxhr.responseText;
var offset = response.length-2;
while ((response.slice(offset).match(/{/g) || []).length
!= (response.slice(offset).match(/}/g) || []).length)
offset = response.slice(0, offset).lastIndexOf('{');
e.jqxhr.responseText = response.slice(offset);
var rawResponse = document.createElement('div');
var txt = document.createElement("textarea");
txt.innerHTML = response.slice(0, offset);
rawResponse.innerHTML = '<' + '!doctype html><' + 'head><' + 'title>Raw HTML<' + '/title><'
+ '/head><' + 'body>' + txt.value + '<' + '/body><' + '/html>'
if (offset > 0) {
winpops=window.open('',"test","fullscreen=no,toolbar=no,status=no,menubar=no,"
+ "scrollbars=yes,resizable=yes,directories=no,location=no,"
+ "width=800,height=480,left=100,top=100,screenX=100,screenY=100");
winpops.document.write(rawResponse.innerHTML);
winpops.focus();
winpops = null;
}
The above code will popup a window whenever you have raw HTML before the actual JSON output and pass rest of the (JSON) output. You can modify it to process the output according to the mime or other parameters and open them in new (popup) window.
It would be really nice if the browser could support non-json resources, for example images, pdf or plain html. Perhaps it is possible to detect the media type of a resource and display it directly in a iframe when it is not json.