![Firefox logo](https://assets-prod.sumo.prod.webservices.mozgcp.net/media/uploads/products/2020-04-14-08-36-13-8dda6f.png)
What standard, if any, specifies how a browser responds to a content type specified by the "type" attribute of the anchor tag?
I had hoped that the following HTML code would FORCE the browser responding to the anchor by treating the content as plain text: <a href="file:path" type="text/plain">anchor text</a>. Likewise: <a href="file:path" type="text/html">...</a> should FORCE the browser to treat the responding reference as HTML code. Firefox does this (good for you!). However, Google Chrome and Internet Explorer seem to ignore the given content type and treat the response according to however they feel (which seems to be according to the file extension). I was hoping to find a standard that describes how a browser handles a source-specified content type. I have looked at W3C's html and http standards and have yet to find any applicable description or requirement. Obviously I am looking for some way to code the source file so that when anchors are followed, they are displayed as I want them to be. I can not change the destination file content (or name) -- that is already determined by its own needs.
Giải pháp được chọn
Hi asicchecker, regarding what is "required", did you follow Gingerbread Man's links?
These are more direct:
HTML 4.01: http://www.w3.org/TR/html401/struct/links.html#h-12.2
HTML5: http://www.w3.org/TR/html5/links.html#attr-hyperlink-type (same)
MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-type
Đọc câu trả lời này trong ngữ cảnh 👍 1Tất cả các câu trả lời (5)
asicchecker wrote:
Google Chrome and Internet Explorer seem to ignore the given content type and treat the response according to however they feel (which seems to be according to the file extension).
Is your server not sending a Content-Type header? Does the document lack a meta content-type tag? Either of those could take precedence over the link's type attribute.
asicchecker wrote:
I have looked at W3C's html and http standards and have yet to find any applicable description or requirement.
My Server is my browser (which I would also claim is my Client). When using a File scheme of the URI, the file requester (the browser when I click on an anchor) has no other http entity to from which to request the file. The browser gets the file locally from the operating system, and "returns" the file to itself. The same browser then renders the returned file according to some rule (including content type).
Perhaps the browser is supposed to send a Content-Type header to its own child process. If so, how could I tell?
With a local file, there is no server response header to tell the browser what content-type the file is, so the browser has to use the extension name for that.
Clearly, the browser does not "have to" use the extension. Firefox does not. Since Firefox (and any other browser) already "knows" that the anchor has been given a content-type, it can use that given type -- although some other browsers choose not to. Further, my question is whether or not this is required by some HTTP/HTML/Browser/URI/MIME standard (and if so, where).
Giải pháp được chọn
Hi asicchecker, regarding what is "required", did you follow Gingerbread Man's links?
These are more direct:
HTML 4.01: http://www.w3.org/TR/html401/struct/links.html#h-12.2
HTML5: http://www.w3.org/TR/html5/links.html#attr-hyperlink-type (same)
MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-type