我正在寻找有关可以在以下代码中更改的帮助(建议),以确保在任何浏览器中都不会显示(隐藏)隐藏令牌。我在 IE7 中的以下代码没有问题,另一方面,Chrome 或 Firefox.IE10 不喜欢某些东西,并且隐藏的令牌显示在屏幕上
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<script type="text/javascript">
WF.onWRIAReady({},
function() {
WF.onDOMReady(addCsrfToken);
});
function addCsrfToken() {
var csrf = '<c:out value="${sessionScope['csrfToken']}" />';
//alert(csrf);
for (var i = 0; i < document.forms.length; i++) {
currentForm = document.forms[i];
addHiddenInputField(currentForm, "csrfToken", csrf);
}
}
function addHiddenInputField(formElement, fieldName, fieldValue) {
var existingElement = null;
for (var i = 0; i < formElement.elements.length; i++) {
if (formElement.elements[i].name == fieldName) {
existingElement = formElement.elements[i];
break;
}
}
if (existingElement == null) {
var inputElement = document.createElement("input");
inputElement.setAttributeNode(createHtmlAttribute("type", "hidden"));
inputElement.setAttributeNode(createHtmlAttribute("name", fieldName));
inputElement.setAttributeNode(createHtmlAttribute("id", fieldName));
inputElement.setAttributeNode(createHtmlAttribute("value", fieldValue));
formElement.appendChild(inputElement);
}
else {
existingElement.value = fieldValue;
}
}
function createHtmlAttribute(name, value) {
var attribute = document.createAttribute(name);
attribute.nodeValue = value;
return attribute;
}
提前感谢您对我的问题的任何帮助