2011-10-17 2 views
2

누군가는 왜 window.location이 ie8 (어쩌면 ie7)에서 정의되지 않았지만 document.location으로 작동하는지 알고 있습니다?window.location은 ie8에서 정의되지 않았습니다

다른 프로젝트의 다른 파일에 비슷한 코드가 있지만 IE에 문제가없는 이유를 찾을 수 없습니다.

'window.location.hash가 null이거나 jquery 1.6.4 line 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> 

JS 부분 :

이 IE 9에서 작동하지 않습니다하지만 프로젝트에서 뭔가, window.location를 오버라이드 (override) 할 수있다
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); 
} 
+3

''이 누락 되었습니까? 아니면 붙여 넣지 않았습니까? – canon

+0

IE에서 * 문제가 있습니까? 아니면 다른 브라우저들? 'location'이라는 이름의 변수가 있습니까? – user113716

+0

바로 IE입니다. 이런 식으로, @ Ӫ _._ Ӫ –

답변

6

:

var location; 

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

delete 연산자를 사용하여 변수를 삭제할 수 있습니다 (비록 technicall Y 당신은 할 수 없어야하지만, 작업을 수행) :

delete location; 

그러나 가장 좋은 방법은 파일 코드의 잘못된 부분을 찾아하는 것입니다.

+1

IE8에서 이것을 확인했습니다. 그것은 무서운 것들입니다. –

+0

나는 더 나쁜 것을했다. 'window = $ (document.window);'. 자, 나는 엉망진창을 보았다. 왜이 버그 코드가 다른 브라우저에서 작동합니까?! 감사! –

+0

이것은 버그가 아닙니다. 이것은 의도적으로 다른 브라우저에서도 마찬가지입니다. 전역 범위에서'var 위치 '를 정의하면 전역 변수이므로'window.location'과 같습니다. 무섭고 잠재적으로 위험한 것 같지만 JavaScript가 작동하는 방식을 이해하는 것은 기술적으로 올바른 동작임을 보여줍니다. 나는 조금 바보 같지만 배울 수있는 더 좋은 방법은 없을까? :) –

관련 문제