关于使浏览器崩溃的代码尝试

之前看了这边文章http://www.cnblogs.com/wiky/archive/2010/01/16/website-makes-browser-crash-reasons.html ,觉得写得很好,推荐一下。我在这边尝试了下里面的第一种原因。

第一种原因总结说就是js内存泄露的原因,具体的可以看上面的文章(真的很棒~呵呵)

尝试代码如下:

html如下

<!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=gb2312" />
<title>无标题文档</title>
<script src="script/ex.js" type="text/javascript"></script>
</head>

<body>
<div id="hello">hello</div>
</body>
</html>

相应的js代码(在文章提到的代码中加了无限循环)

var obj;
window.onload = function(){
    // JavaScript对象obj到DOM对象的引用,根据id获得
	for(;1;){
    obj=document.getElementById("hello");
  // DOM 对象则有到此 JavaScript 对象的引用,由expandoProperty实现
  document.getElementById("hello").expandoProperty=obj;
	}
};
 浏览器如预期的崩溃.....
posted @ 2011-03-05 17:02  akawhy  阅读(788)  评论(0编辑  收藏  举报