Jump to content

JavaScript in all browsers except IE


Guest FirefoxRocks
 Share

Recommended Posts

Guest FirefoxRocks

Ok this is kinda cool actually, but anyways, here are some code samples:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en-CA"><head><title>JavaScript application test</title></head><body><script type="application/javascript">	document.write("It works!");</script></body></html>

This one works in Firefox (and other Gecko-based browsers), Opera and Safari (I only tested Windows). Here is the next one:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en-CA"><head><title>JavaScript application test</title></head><body><script type="text/javascript">	document.write("It works!");</script></body></html>

This one works in the above browsers and Internet Explorer. Now in XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1_strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-CA" lang="en-CA"><head><title>JavaScript application test</title></head><body><script type="application/javascript"><!--//--><![CDATA[//><!--	document.write("It works!");//--><!]]></script></body></html>

This works the same as the first HTML example. Now for a small change:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1_strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-CA" lang="en-CA"><head><title>JavaScript application test</title></head><body><script type="text/javascript"><!--//--><![CDATA[//><!--	document.write("It works!");//--><!]]></script></body></html>

This example works as the second HTML example. All of these have also been tested in XHTML Transitional also. The browsers that were used were Firefox 2.0.0.11, Opera 9.25, Safari 3.0.4 and Internet Explorer 7.From these tests, I conclude that application/javascript does not work in Internet Explorer but works properly in the other browsers. Interesting, huh?

Link to comment
Share on other sites

From these tests, I conclude that application/javascript does not work in Internet Explorer but works properly in the other browsers. Interesting, huh?
I think the new Acid3 test actually tests this. Seems Ian Hickson (or anyone that helped him) already discovered this bug long ago.Anyhow, what seems more interesting to me is that web servers always serve ".js" files with the "application/javascript" MIME type, yet IE uses them if you use the proper "type" attribute.I suppose it's because of the way IE and other browsers treat MIME types in general.Non-IE browsers use the MIME type provided by the server, and fallback to the one supplied in the "type" attribute if it fails. If a "type" attribute is not present or fails, they try to parse the file in different fashions in an attempt to guess the MIME type.IE uses the "type" attribute and if it's missing, uses the one from the server. If parsing with that MIME type fails, it tries parsing the file in a different fashion, eventually showing the parsing that didn't produced any errors, falling back to "text/plain" if there was no such type.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...