2014-09-26 5 views
0

출력 인코딩에 esapi를 사용하고 있습니다. 그러나, 그 이상한 일.외부 js가로드되기 전에 실행되는 Js 문

<html> 
    <head> 
    <title> AC </title> 
    </head> 
    <body> 
     <style type="text/css"> 
     .ac-container { 
      font-family: Verdana,Arial,Helvetica,sans-serif; 
      font-size: 12px; 
      table-layout: fixed; 
      border-collapse: collapse; 
      width: 100%; 
      border: 6px solid #BFCAFF; 
      background-color: #F5F8FD; 
     } 
     .ac-close { color: #FF0000;float: right; cursor: pointer; } 
     .ac-header { color: #0771D4; background-color: #E4EFFA; padding: 5px; font-weight: bold; border-bottom: 1px solid #B0D2F1; } 
     .ac-search { padding: 3px 3px 0; } 
     .ac-search table { background-color: #fff; border: 1px solid #BDCED5; width: 100%; } 
     .ac-search-td1 { width: 18px; } 
     .ac-search-td2 input { width: 100%; border: none; } 
     .ac-searchico { 
      float: left; height:18px; width:18px; 
     } 
     .ac-categories { padding: 3px 3px; float: right; width: 70%; } 
     .ac-categories select { 
      width: 100%; 
      color: #000; 
      border: 1px solid #BDCED5; 
      font-size: 11px; 
      padding: 2px 0; 
      font-family: Verdana,Arial,Helvetica,sans-serif; 
      font-weight: bold; 
     } 
     .ac-categories option { font-weight: normal; } 
     .ac-cts-nm { font-weight: bold; float: left; } 
     .ac-cts-mail { color: #777; } 
     .ac-cts-row, .ac-cts-row-sel { padding: 5px 0; cursor: pointer; float: left; width: 100%; overflow: hidden; border-bottom: 1px solid #E3E4DF; white-space: nowrap; } 
     .ac-cts-row-sel { background-color: #FEFAD1; border-bottom: 1px solid #EBE5C3; } 
     .ac-cts-nm, .ac-cts-mail { 
      float: left; padding: 0; margin: 0; margin-left: 3px; 
      color: #737373; 
     } 
     .ac-cts-mail { clear: both; font-size: 11px; margin-left: 21px; color: #9E9E9E; } 
     .ac-cts-row em, .ac-cts-row-sel em, .ac-selectall em, .ac-selectall-check em { 
      clear: both; font-size: 11px; margin-left: 21px; color: #9E9E9E; 
      float:left; display: block; width: 16px; height: 16px; cursor: pointer; 
      margin-left: 2px; 
     } 
     .ac-cts-row-sel em, .ac-selectall-check em { background-position: -22px -139px; } 
     .ac-button { padding: 5px; margin: 0 auto; text-align: center; } 
     .ac-firstico, .ac-Dfirstico, .ac-lastico, .ac-Dlastico, .ac-previco, .ac-Dprevico, .ac-nextico, .ac-Dnextico { 
      width: 20px; height: 16px; cursor: pointer; margin-right: 3px; 
     } 
     .ac-Dfirstico { background-position: -4px -90px; } 
     .ac-previco { background-position: -70px -114px; } 
     .ac-Dprevico { background-position: -28px -90px; } 
     .ac-nextico { background-position: -43px -90px; } 
     .ac-Dnextico { background-position: -1px -114px; } 
     .ac-lastico { background-position: -67px -90px; } 
     .ac-Dlastico { background-position: -25px -114px; } 
     .ac-navigation { 
      background-color: #F5F8FD; 
      border: 1px solid #CEE1F0; border-left: none; border-right: none; 
      color:#9E9E9E; font-size:11px;font-weight:bold; 
      padding:2px; 
      text-align:center; 
     } 
     .ac-nav-page { 
      display:inline; 
      margin:0 5px; 
      vertical-align:super; 
     } 
     .ac-navigation select { font-size:10px; border: 1px solid #BDCED5; } 
     .ac-selectall, .ac-selectall-check { width: 25%; overflow: hidden; color: #000; font-weight: normal; font-size: 11px; padding: 1px 0 4px; float: left;margin-top:3px;padding:3px 0; } 
     .ac-selectall div, .ac-selectall-check div { margin-top: 1px; white-space: nowrap;cursor: default; } 
     .ac-nocts { 
      padding: 5px;color: #aaa;text-align: center;font-weight: bold; 
     } 
     .ac-loading { 
      background-color:#0568B2; 
      color:#FFFFFF; 
      font-weight:bold; 
      height:15px; 
      left:40%; 
      padding:4px 10px; 
      position:absolute; 
      top:35%; 
      z-index:2001; 
      display: none; 
     } 
     .ac-button input, .ac-button input:hover { 
      background-color:#74A1EC; 
      border:1px outset #5983EE; 
      color:#FFFFFF; 
      font-weight:bold; 
      cursor: pointer; 
     } 
    </style> 
    <table class="ac-container" cellpadding="0" cellspacing="0"> 
     <tr> 
      <td class="ac-header"> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <div class="ac-loading" id="ac-loading"> 
       </div> 
       <div class="ac-search"> 
        <table cellspacing="0" cellpadding="0"> 
         <tr> 
          <td class="ac-search-td1"> 
           <span class="ac-searchico"></span> 
          </td> 
          <td class="ac-search-td2"> 
          </td> 
         </tr> 
        </table> 
       </div> 
       </div> 
       <div class="ac-selectall" id="ac-selectall"> 
        <em class="ac-uncheck" onclick="AC.selectAll(this.parentNode);"></em> 
       </div> 
       <div class="ac-cts-container" id="ac-cts-container"> 
       </div> 
       </td> 
      </tr> 
    </table> 
    <script> 
    //Adding dummy var to ignore esapi dependency error. 
    var ESAPI_Standard_en_US = { 
    }; 
    <script src="/esapi/esapi-compressed.js" type="text/javascript"></script> 
    <script src="/esapi/Base.esapi.properties.js" type="text/javascript"></script> 
    <script> 
     // Initialize the api 
     org.owasp.esapi.ESAPI.initialize(); 
    </script> 
</body> 
</html> 

가 외부 JS 전에 호출이 문 "org.owasp.esapi.ESAPI.initialize()가"로드

코드입니다. 그래서 "org"가 정의되지 않았습니다.

크롬과 파이어 폭스를 확인한 결과, 두 브라우저에서 모두 동일한 문제가 발생했습니다. 이것은 정상적인 행동입니까? 외부 js가 동 기적으로로드되기를 바랍니다.

이 페이지는 iframe을 사용하여 다른 페이지에 삽입되었습니다.

이 문제를 어떻게 해결할 수 있습니까?

답변

2

자바 스크립트
당신은 DOM이로드 될 때까지 함수를 호출 기다려야한다. JS 버전에 대한

if (window.addEventListener) // W3C standard 
{ 
    window.addEventListener('load', fn, false); 
} 
else if (window.attachEvent) // Microsoft 
{ 
    window.attachEvent('onload', fn); 
} 

function fn(){ 
    org.owasp.esapi.ESAPI.initialize(); 
} 

상세 정보 : 순수 JS에서는이 같은 그렇게 할 수 pure JavaScript equivalent to jQuery's $.ready() how to call a function when the page/dom is ready for it

jQuery를
을하지만 그것은 buildin 폴백 (fallback)을 가지고 있기 때문에 jQuery를 사용하는 것이 더 쉽습니다. JQuery와에 : JQuery와 버전에 대한

$(document).ready(function(){ 
    org.owasp.esapi.ESAPI.initialize(); 
}); 

더 많은 정보 : pure JavaScript equivalent to jQuery's $.ready() how to call a function when the page/dom is ready for it

+0

이 페이지는 iframe에 포함되어 있습니다. 'window.onload 또는 window.addEventListener'가 작동하지 않습니다. – kannanrbk

+0

개체가 iframe에 있습니까? document.getElementById ("yourFrame") .contentWindow.org.owasp.esapi.ESAPI.initialize();'(http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an을 참조하십시오. -iframe-from-the-parent-page) –

+0

죄송합니다. 혼란 스럽습니다. 예 : 내 페이지 -> a.html이 일부 x 페이지에 포함되어 있습니다. 문제는 내 페이지 (a.html)에 있습니다. – kannanrbk

1

당신은 window.onload 핸들러 내부에 그 줄을 실행해야합니다.

window.onload은 문서 및 관련 리소스 (외부 스크립트 포함)가로드 된 후 브라우저에서 실행되는 전역 이벤트입니다.