5

The page you are viewing right now has the HTTP header element of Content-type: text/html. HTML displayed normally and JavaScript will be executed. If you have a Content-Type: text/javascript then the JavaScript is not executed, it is only displayed.

My question is: Are there content-type's other than text/html that will execute JavaScript? I wold like as complete of a list as possible for any common browser (IE,Firefox,Chrome,Safari).

6
  • 6
    Maybe you mean which contents types are capable of making javascript execute? Because text/html doesn't execute jasvascript, the <script> tag within the document is one of the execution triggers. Keep in mind this list is potentially limitless when you consider browser plugins and extensions. Commented Jan 19, 2011 at 22:24
  • @Rook Are you searching for an alternative? Commented Jan 19, 2011 at 22:38
  • @Šime Vidas @chris I need a list of all them, this is for QA purposes. Commented Jan 19, 2011 at 22:39
  • @Rook Note that different browsers likely recognize different content types. I wouldn't be surprised if there is a big difference between IE and Safari (on Mac). Are you interested in a specific browser? Commented Jan 19, 2011 at 22:58
  • @Šime Vidas Any of the common browsers. Commented Jan 19, 2011 at 23:34

5 Answers 5

4

I don't know of a full list, and it may well be that no such list exists publicly. You may have to find out for yourself. (Although I don't think anything speaks against setting up a test page with a number of iframes, and asking the SO community to provide data with their respective browsers. It's been done before.)

In Internet Explorer, this one should definitely be on the list:

Candidates that I would test for (because it's conceivable a careless programmer might activate them for HTML parsing) include:

  • application/form-data
  • text/xhtml+xml (used to be proposed in 2000, no idea what happened to that)

However, I tested those with both Chrome 9 and the latest Firefox, and they reject everything except text/html. Firefox shows them as downloadable resources instead, which I think eliminates them from your equation as any JS therein will be executed in the local context rather than the URL's. (IE is executing everything including text/plain for me, but I think that is a header mixup with my server.)

If you want to go for hard-core sure for the Open Source browsers, check their source code or ask on their mailing lists/forums. I have a feeling the good ones have text/html hard-coded.

Edit: Arrgh! Firefox, Chrome and IE parse HTML, and execute scripts, regardless of content type - I successfully managed to set Content-type: text/poppycock - when the resource's extension is .htm or .html. That means that you have to test not only for MIME types, but for file extensions (which should not play any role in HTTP) as well. Didn't know that - this was probably introduced to fix the output of broken web servers. Stuff like this is why I don't work in IT security :)

All tests made on Windows 7.

Sign up to request clarification or add additional context in comments.

1 Comment

File extensions generally doesn't matter, if the Content-Type is unrecognized browsers may resort to MIME-sniffing: mimesniff.spec.whatwg.org
2

application/xhtml+xml would have to execute Javascript. That's the only one I can think of at the top of my head.

Comments

2

This wouldn't be very useful. Javascript has no way to import other scripts, so your script would be isolated from libraries. The only way to tie them together is through HTML. Also, the input/output options are very limited without a document.

1 Comment

Oh ok :) That sounds interesting. What are they?
1

PDF files can also execute javascript (application/pdf).

Aswell as XML documents (application/xml), including SVG (image/svg+xml), for example:

<?xml version="1.0" encoding="utf-8"?>
<document>
<script xmlns="http://www.w3.org/1999/xhtml" src="xml.js"></script>
</document>

Comments

-1

Have you tried application/javascript?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.