Rat*_*ata 2 javascript jquery html5
任何人都知道为什么window.location在ie8中未定义(也许是ie7),但是作为document.location工作?
我找不到为什么另一个文件来自其他项目有类似的代码,但IE没有问题.
我也得到了一个奇怪的错误:'window.location.hash为null或者不是jquery 1.6.4第2行中的对象'.我也尝试了1.5.1,但同样的错误.
标题:
<html lang="">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="assets/css/style.css">
<script src="assets/js/jquery.1.6.4.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="assets/js/jquery.easing.1.3.js"></script>
<script src="assets/js/jquery.ba-hashchange.min.js"></script>
<script src="assets/js/script.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
JS部分:
if( window.onhashchange )
{
window.onhashchange = function()
{
hashChanged( window.location.hash );
}
}
else
{
var storedHash = window.location.hash;
window.setInterval( function()
{
if( window.location.hash != storedHash )
{
storedHash = window.location.hash;
hashChanged( storedHash );
}
}, 100 );
}
Run Code Online (Sandbox Code Playgroud)
您的项目中的某些内容可能会重写window.location,但这在IE 9中不起作用:
var location;
alert(window.location);
//-> "undefined"
Run Code Online (Sandbox Code Playgroud)
您可以使用delete运算符删除变量(虽然从技术上讲,您应该不能,但它确实有效):
delete location;
Run Code Online (Sandbox Code Playgroud)
但最好的解决方案是在文件中查找有问题的代码.