---
title: "Javascript死在type属性"
author: "faiinlove"
date: "2009-11-01T15:34:45Z"
tags: []
categories: ["Web前端"]
slug: "javascript-type"
draft: false
lastmod: "2009-11-05T18:17:37Z"
id: 508106
url: "https://obatu.iteye.com/blog/508106"
---

[博客地址： http://baicaier.iteye.com/](http://baicaier.iteye.com/ "查看更多")

昨天修改一个页面，是用的js的document.location做跳转的，在火狐下面有测试通过了，在IE6下突然就发现不行了！

然后看了页面，一个很简单的页面：

 

```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统提示 - 百才招聘 www.baicai.com</title>
</head>
<body>
<script type="application/javascript" language="javascript">
<!--
	var action = '{action}';
	if(action == 'pwd'){
		if(window.confirm('密码不对，现在取回密码吗？')){
			window.location = '/personal/forget.html';
		}else{
			window.location = '/personal/login.html';
		}
	}else{
		if(window.confirm('帐号不存在，现在注册吗？')){
			window.location = '/personal/register.html';
		}else{
			window.location = '/personal/login.html';
		}
	}
-->
</script>
</body>
</html>

```

 这个页面很简单，但是里面的几个简单JS没有执行，为何？？？

我看了下，与平时写的javascript唯一的不同之处就是这里了：&lt;script type='application/javascript'......

平时我们是写:text/javascript。

改回来，重新测试。

OK！！！！

怪了！这两个有什么区别呢？google一下。

来看一段google到的结果：

 

 写道

javaScript的type属性有使用text/javascript的，也有使用application/javascript的还有使用appliation/x-javascript的，所有就不太知道这三个mime 类型有什么区别，在google上一搜：

The traditional MIME type for JavaScript programs is  
"text/javascript". Another type that has been used is  
"application/x-javascript" (the "x" prefix indicates that it is an  
experimental, nonstandard type). RFC 4329 standardized the  
"text/javascript" type because it is in common use. However, because  
JavaScript programs are not really text documents, it marks this type  
as obsolete and recommends "application/javascript" (without the "x-")  
instead. At the time of this writing, "application/javascript" is not  
well supported, however. That might be the reason why  
"application/x-javascript" is used by a lot of webpages.

大致意思是：传统的javascript程序的MIME类型是“text/javascript”，其他使用的还有"application/x-javascript"（x前缀表示这是实验性的，不是标准的类型），RFC4329规定了“text/javascript”类型，因为它普遍被使用。然而，javascript程序并不是真正的文本文件，这就表示这个类型已经意味着过时了，而推荐使用"application/javascript"（去除x前缀）。然而，在写程序的时候，"application/javascript"没有很好的支持。这也行就是"application/x-javascript"被使用在很多网页中的原因。

 原因出来了，浏览器的差异，互联网的各种标准导致了不统一。

换回原始的"text/javascript"，原始社会好！