2012-05-23 1 views
0

에 보안 오류 1000가 발생 나는 그것이 짧은 만들 수 있습니다 :

내가 객체 반사 코드의 어떤 종류를 만들기위한 window 객체의 내부에 사용 가능한 모든 기능과 객체를 열거 형 싶다.
Firefox에서는 모든 브라우저에서 정상적으로 실행됩니다. 여기 내 의사 루프 코드 :파이어 폭스는이 간단한 열거

var all_names=[]; 
for (var i in window) 
{ 
    //if it's NOT an object 
    all_name.push(i.toString()); 
    //if it's an object   
    enum up to 3 more levels in child objects. 
} 

그리고 나는 그런 getOwnPropertyNames 파이어 폭스에서 사용 가능한 API를 사용하지 않습니다.
그럼 어떻게해야합니까? 자바 스크립트의 열거에 대한 더 나은 솔루션 (물론 크로스 브라우저) 여기


좀 더 기술적 인 정보가된다 :

정확한 파이어 폭스 오류 :

[20:48:04.539] uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "http://localhost/test/common.js Line: 53"]

정확한 열거 형 루프 코드 : 내가 페이지에 iframe이를 열어 비슷한 짓을

function reflectAsString() { 
    try{ 
     var m1 = ""; 
     var m2 = ""; 
     var m3 = ""; 
     for (var i in window) { 
      if(window[i] && window[i]!= null && window[i] != "globalStorage") 
       { 
       m1 += i; 
       first_instance = window[i]; 
       if(typeof first_instance == "object") 
        { 
        for(var j in first_instance) 
        { 
         if(first_instance[j] && first_instance[j]!= null) 
          { 
          m2 += j; 
          second_instance = first_instance[j]; 
          if(typeof second_instance == "object") 
           { 
           for (var k in second_instance) 
           { 
            if(second_instance[k] && second_instance[k]!= null) 
             { 
             m3 += k; 
            } 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
     return hex_md5(hex_md5(m1)+hex_md5(m2)+hex_md5(m3)); 
    } catch(e) { 
     try { 
      var strToHash = Object.getOwnPropertyNames(window).filter(function(property) { 
       return typeof window[property] == 'function'; 
      }); 
      return hex_md5(strToHash.toString()); 
     } catch(e2) { 
      return "undef"; 
     } 
    } 
} 
+1

알아 내기 위해 너무 열심히해서는 안됩니다 * 알이 오류의 원인이된다. 그렇게하면 문제를 해결하거나 문제를 해결할 수있는 충분한 정보를 얻을 수 있습니다. –

+0

@KirkWoll 나는 globalStorage가 더 이상 사용되지 않으며 이와 같이 액세스하면 이러한 오류가 발생할 것이라고 생각합니다. – Sepehr

답변

1

관심이 있고 iframe의 윈도우에있는 전역과 부모 윈도우에있는 전역을 비교합니다. 오류가있는 경우 try 블록은 오류 플래그가있는 특성 이름을 리턴합니다. iframe이 SRC에 대한

HTML은 : 윈도우 등 아래 속성을 *

<html lang= "en"> 
<head> 
<meta charset= "utf-8"> 
<title>Get Globals</title> 
<style> 
p{border:none;font-size:1.25em;font-weight:600;} 
h2{color:navy;border-top:3px ridge navy;margin:1ex 0;} 
span{margin:0 1em;} 
</style> 
<script> 
navigator.sayswho= (function(){ 
    var N= navigator.appName, ua= navigator.userAgent, tem, 
    ie= navigator.IEmod, 
    M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*([\d\.]+)/i); 
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1]; 
    M= M? [M[1], M[2]]:[N, navigator.appVersion, '-?']; 
    if(ie && ie!= M[1]) M[2]= 'ie mode:'+navigator.IEmod; 
    return M.join(' '); 
})(); 
window.onload= function(){ 
    if(this!= top){ 
     var G={ 
      getInterface:1, InstallTrigger:1 
     }, 
     B= [], C= [], k= ['HTML elements:'], d= navigator.sayswho || '', 
     t= document.getElementsByTagName('p'); 
     for(var p in this) G[p]= 1; 
     for(var key in top){ 
      try{ 
       if(!(key in G)){ 
        if(top[key].nodeType== 1) k.push(key); 
        else B.push(key); 
       } 
       else C.push(key); 
      } 
      catch(er){ 
       B.push('error with '+key); 
      } 
     } 
     if(k.length>1) B.push(k.join(' ')); 
     if(d) document.getElementsByTagName('span')[0].innerHTML+= d; 
     t[0].innerHTML= B.join('<br>'); 
     t[1].innerHTML= C.sort().join(', '); 
    } 
} 
</script> 
</head> 
<body> 
<h1>Globals<span>in</span></h1> 
<h2>New globals defined in the top window</h2> 
<p></p> 
<h2>Common window properties</h2> 
<p></p> 
</body> 
</html> 
+0

코드에 필요한 것을 찾았습니다. 감사합니다. 매우 도움이됩니다. – Sepehr