我正在使用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>
本聲明 「org.owasp.esapi.ESAPI.initialize()」 外部JS調用之前被加載。所以,我得到的「org」是未定義的。
我檢查了Chrome和Firefox,在兩個瀏覽器中都遇到同樣的問題。這是正常的行爲嗎?我希望,外部js正在同步加載。
此頁面嵌入在使用iframe的其他頁面中。
我該如何解決這個問題?
此頁面包含在iframe中。 'window.onload或window.addEventListener'不工作。 – kannanrbk 2014-09-26 13:20:30
所以對象是在iframe?比使用'document.getElementById(「yourFrame」)。contentWindow.org.owasp.esapi.ESAPI.initialize();'(參見http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an - 從父母的頁面) – 2014-09-26 13:28:44
對不起,我想我迷茫你。 例如: MyPage - > a.html嵌入在某個x頁面中。