开发者

window.location is undefined in ie8

开发者 https://www.devze.com 2023-04-13 09:43 出处:网络
Anybody knows why window.location is undefined in ie8 (maybe ie7 too), but works as document.location?

Anybody knows why window.location is undefined in ie8 (maybe ie7 too), but works as document.location?

I couldn't find why another file, from other project has a similar code but hasn't a probl开发者_运维技巧em with IE.

I'm get a weird error too: 'window.location.hash is null or not an object in jquery 1.6.4 line 2'. I tried 1.5.1 too, but same error.

The header:

<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>

The JS part:

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 );
}


Something in your project may be overriding window.location, though this won't work in IE 9:

var location;

alert(window.location);
//-> "undefined"

You could use the delete operator to delete the variable (although technically you shouldn't be able to, but it does work):

delete location;

But the best solution would be to look for the offending piece of code in your file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号