Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support view of non-json resources #42

Open
erikvanoosten opened this issue May 27, 2014 · 1 comment
Open

Support view of non-json resources #42

erikvanoosten opened this issue May 27, 2014 · 1 comment

Comments

@erikvanoosten
Copy link

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.

@vdhatterwal
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants