javascript - window.location is undefined in ie8 - Stack Overflow

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

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 problem 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=".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 );
}

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 problem 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./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 );
}
Share Improve this question edited Aug 3, 2017 at 16:45 MrBoJangles 12.2k17 gold badges64 silver badges82 bronze badges asked Oct 17, 2011 at 16:57 Ratata TataRatata Tata 2,8791 gold badge37 silver badges49 bronze badges 3
  • 3 Are you missing <!DOCTYPE html> or did you not paste that? – canon Commented Oct 17, 2011 at 16:59
  • Is it just an issue in IE? Or other browsers too? Do you have any variables named location? – user113716 Commented Oct 17, 2011 at 17:07
  • Just IE. Was something like this, @Ӫ_._Ӫ – Ratata Tata Commented Oct 17, 2011 at 17:18
Add a ment  | 

1 Answer 1

Reset to default 6

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742382161a4433335.html

相关推荐

  • javascript - window.location is undefined in ie8 - Stack Overflow

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

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信