如何解决asp .Net中的Java脚本
| 我在asp.Net页面中收到WebResource错误:var __pendingCallbacks = new Array();
Microsoft JScript runtime error: \'Array\' is undefined
我不知道什么可能导致这种情况发生。数组不是Java本身的一部分吗?任何帮助,将不胜感激。
编辑
问题是这不是我写的代码,它内置在asp.Net的页面结构中。
编辑
仅在IE9中和仅在IE9模式下运行时才出现此问题(不兼容)
码:
(这是动态生成的代码,很抱歉,长度。问题大约在一半)
function WebForm_PostBackOptions(eventTarget,eventArgument,validation,validationGroup,actionUrl,trackFocus,clientSubmit) {
this.eventTarget = eventTarget;
this.eventArgument = eventArgument;
this.validation = validation;
this.validationGroup = validationGroup;
this.actionUrl = actionUrl;
this.trackFocus = trackFocus;
this.clientSubmit = clientSubmit;
}
function WebForm_DoPostBackWithOptions(options) {
var validationResult = true;
if (options.validation) {
if (typeof(Page_ClientValidate) == \'function\') {
validationResult = Page_ClientValidate(options.validationGroup);
}
}
if (validationResult) {
if ((typeof(options.actionUrl) != \"undefined\") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
theForm.action = options.actionUrl;
}
if (options.trackFocus) {
var lastFocus = theForm.elements[\"__LASTFOCUS\"];
if ((typeof(lastFocus) != \"undefined\") && (lastFocus != null)) {
if (typeof(document.activeElement) == \"undefined\") {
lastFocus.value = options.eventTarget;
}
else {
var active = document.activeElement;
if ((typeof(active) != \"undefined\") && (active != null)) {
if ((typeof(active.id) != \"undefined\") && (active.id != null) && (active.id.length > 0)) {
lastFocus.value = active.id;
}
else if (typeof(active.name) != \"undefined\") {
lastFocus.value = active.name;
}
}
}
}
}
}
if (options.clientSubmit) {
__doPostBack(options.eventTarget,options.eventArgument);
}
}
var __pendingCallbacks = new Array();
var __synchronousCallBackIndex = -1;
function WebForm_DoCallback(eventTarget,eventCallback,context,errorCallback,useAsync) {
var postData = __theFormPostData +
\"__CALLBACKID=\" + WebForm_EncodeCallback(eventTarget) +
\"&__CALLBACKPARAM=\" + WebForm_EncodeCallback(eventArgument);
if (theForm[\"__EVENTVALIDATION\"]) {
postData += \"&__EVENTVALIDATION=\" + WebForm_EncodeCallback(theForm[\"__EVENTVALIDATION\"].value);
}
var xmlRequest,e;
try {
xmlRequest = new XMLHttpRequest();
}
catch(e) {
try {
xmlRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");
}
catch(e) {
}
}
var setRequestHeaderMethodExists = true;
try {
setRequestHeaderMethodExists = (xmlRequest && xmlRequest.setRequestHeader);
}
catch(e) {}
var callback = new Object();
callback.eventCallback = eventCallback;
callback.context = context;
callback.errorCallback = errorCallback;
callback.async = useAsync;
var callbackIndex = WebForm_FillFirstAvailableSlot(__pendingCallbacks,callback);
if (!useAsync) {
if (__synchronousCallBackIndex != -1) {
__pendingCallbacks[__synchronousCallBackIndex] = null;
}
__synchronousCallBackIndex = callbackIndex;
}
if (setRequestHeaderMethodExists) {
xmlRequest.onreadystatechange = WebForm_CallbackComplete;
callback.xmlRequest = xmlRequest;
xmlRequest.open(\"POST\",theForm.action,true);
xmlRequest.setRequestHeader(\"Content-Type\",\"application/x-www-form-urlencoded; charset=utf-8\");
xmlRequest.send(postData);
return;
}
callback.xmlRequest = new Object();
var callbackFrameID = \"__CALLBACKFRAME\" + callbackIndex;
var xmlRequestFrame = document.frames[callbackFrameID];
if (!xmlRequestFrame) {
xmlRequestFrame = document.createElement(\"IFRAME\");
xmlRequestFrame.width = \"1\";
xmlRequestFrame.height = \"1\";
xmlRequestFrame.frameBorder = \"0\";
xmlRequestFrame.id = callbackFrameID;
xmlRequestFrame.name = callbackFrameID;
xmlRequestFrame.style.position = \"absolute\";
xmlRequestFrame.style.top = \"-100px\"
xmlRequestFrame.style.left = \"-100px\";
try {
if (callBackFrameUrl) {
xmlRequestFrame.src = callBackFrameUrl;
}
}
catch(e) {}
document.body.appendChild(xmlRequestFrame);
}
var interval = window.setInterval(function() {
xmlRequestFrame = document.frames[callbackFrameID];
if (xmlRequestFrame && xmlRequestFrame.document) {
window.clearInterval(interval);
xmlRequestFrame.document.write(\"\");
xmlRequestFrame.document.close();
xmlRequestFrame.document.write(\'<html><body><form method=\"post\"><input type=\"hidden\" name=\"__CALLBACKLOADSCRIPT\" value=\"t\"></form></body></html>\');
xmlRequestFrame.document.close();
xmlRequestFrame.document.forms[0].action = theForm.action;
var count = __theFormPostCollection.length;
var element;
for (var i = 0; i < count; i++) {
element = __theFormPostCollection[i];
if (element) {
var fieldElement = xmlRequestFrame.document.createElement(\"INPUT\");
fieldElement.type = \"hidden\";
fieldElement.name = element.name;
fieldElement.value = element.value;
xmlRequestFrame.document.forms[0].appendChild(fieldElement);
}
}
var callbackIdFieldElement = xmlRequestFrame.document.createElement(\"INPUT\");
callbackIdFieldElement.type = \"hidden\";
callbackIdFieldElement.name = \"__CALLBACKID\";
callbackIdFieldElement.value = eventTarget;
xmlRequestFrame.document.forms[0].appendChild(callbackIdFieldElement);
var callbackParamFieldElement = xmlRequestFrame.document.createElement(\"INPUT\");
callbackParamFieldElement.type = \"hidden\";
callbackParamFieldElement.name = \"__CALLBACKPARAM\";
callbackParamFieldElement.value = eventArgument;
xmlRequestFrame.document.forms[0].appendChild(callbackParamFieldElement);
if (theForm[\"__EVENTVALIDATION\"]) {
var callbackValidationFieldElement = xmlRequestFrame.document.createElement(\"INPUT\");
callbackValidationFieldElement.type = \"hidden\";
callbackValidationFieldElement.name = \"__EVENTVALIDATION\";
callbackValidationFieldElement.value = theForm[\"__EVENTVALIDATION\"].value;
xmlRequestFrame.document.forms[0].appendChild(callbackValidationFieldElement);
}
var callbackIndexFieldElement = xmlRequestFrame.document.createElement(\"INPUT\");
callbackIndexFieldElement.type = \"hidden\";
callbackIndexFieldElement.name = \"__CALLBACKINDEX\";
callbackIndexFieldElement.value = callbackIndex;
xmlRequestFrame.document.forms[0].appendChild(callbackIndexFieldElement);
xmlRequestFrame.document.forms[0].submit();
}
},10);
}
解决方法
发生这种情况是因为我们有此设置
<collapsible panel>
<iframe>
<script>
</script>
</iframe>
</collapsible panel>
加载页面时,显示的面板会在加载javascript库之前强制将iframe中的脚本拖到DOM中。这似乎是对IE9所做的更改。我还没有解决这个问题的方法,但至少我知道原因。临时的解决方法是使用其他标记强制页面与IE8的兼容性,以防其他人遇到此问题。
, 当我从iframe中删除SRC属性并将onOpen事件添加到jQuery \的对话框时,该问题已修复:
open: function(){
document.getElementById(\"iframename\").src = \"page.aspx\";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。