W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2014

Re: [whatwg] HTTP status code from JavaScript

From: Mathias Bynens <mathiasb@opera.com>
Date: Sun, 25 May 2014 10:21:28 +0200
Message-Id: <5251A1AF-02F4-4F62-A918-66BBB6CD1712@opera.com>
To: Tobie Langel <tobie.langel@gmail.com>
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Michael Heuberger <michael.heuberger@binarykitchen.com>
On 25 May 2014, at 09:58, Tobie Langel <tobie.langel@gmail.com> wrote:

> 
>> * Adding inline JS <script> slows down the page load.
> 
> In that case, use a meta tag:
> 
> <meta name=http-status content=404>
> 
> Then in JS:
> 
> var status = parseInt(document.querySelector("meta[name=http-status]").getAttribute("content"));

Since `http-status` is not a registered metadata name (http://wiki.whatwg.org/wiki/MetaExtensions) it might be better to use a custom `data-*` attribute. It could be added to any element, e.g.

    <body data-http-status=404>

Then in JavaScript:

    var status = Number(document.body.dataset.httpStatus);
Received on Sunday, 25 May 2014 08:21:57 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:20 UTC