gpt4 book ai didi

javascript - 当我打印arguments.callee.caller在IE浏览器以外的浏览器中为null时,结果为null

转载 作者:行者123 更新时间:2023-11-28 06:58:19 25 4
gpt4 key购买 nike

我正在通过使用 window.onerror 方法来利用全局异常。我试图通过在 IE 中使用 arguments.callee.caller 来获取函数名称。但在 Chrome 和所有其他浏览器中它为空。我用谷歌搜索了很多。但我没有得到任何结果。如何在 chrome/mozilla 中获取调用者的值?请建议我。我给出了下面给出的示例代码。

window.onerror = function (msg, url, line, col, error) {
debugger;
// Note that col & error are new to the HTML 5 spec and may not be
// supported in every browser. It worked for me in Chrome.
var extra = !col ? '' : '\ncolumn: ' + col;
extra += !error ? '' : '\nerror: ' + error;

LineNumber = line;
ColumnNumber = col;
ErrorDescription = error.stack;
//console.log(ErrorDescription);
ErrorString = msg;
var now = new Date();
var datetime = now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate();
ErrorDateTime = datetime + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();

// You can view the information in an alert to see things working like this:
//alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);

var FilePath = window.location.pathname;
PageName = FilePath.split("/").pop();

var ExceptionFunctionName = window.onerror.caller;
if (ExceptionFunctionName != undefined && ExceptionFunctionName != null) {
ExceptionFunctionName = ExceptionFunctionName.substr('function '.length);
MethodName = ExceptionFunctionName.substr(0, ExceptionFunctionName.indexOf('{'));
}
capture();
var suppressErrorAlert = true;
// If you return true, then error alerts (like in older versions of
// Internet Explorer) will be suppressed.
//return suppressErrorAlert;
}

下面给出了我的调用函数。

 function ExceptionFunction() {
var Test = testvar / 5;
}

最佳答案

您需要使用arguments.callee.caller而不是window.onerror.caller

BR,萨尔

关于javascript - 当我打印arguments.callee.caller在IE浏览器以外的浏览器中为null时,结果为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32373745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com