Skip to content

Proposal : response.html() #15

Closed
Closed
@fflorent

Description

@fflorent

window.fetch is a great progress to make asynchronous requests, thanks for that!
I am not sure whether that's the right place for doing so, I also propose that we can parse the response as HTML content.

Something like response.html([context]) where context is the parent node of where the nodes would be inserted. It would return Promise<DocumentFragment>.

A polyfill of them would be:

response.html = function(context) {
  return this.text().then((text) => {
    var range = document.createRange();
    range.selectNodeContents(context);
    return range.createContextualRange(text);
  };
};

Use case: having directly parsed elements to possibly manipulate their content before inserting.

What do you think?

Florent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions