1

We want to log the JavaScript on our Website. For that I am overwriting the log functionality with my own implementation.

On the server side we are using Log4Net for our logging. My idea now is to capture the log on the client side and send it to the server with ajax. How ever I don't want to send the Ajax request every time someone types log. So my idea was to catch all the logs and send ONE request after the call-stack ended up where it has began.

Is there an event or a way to detect when call-stack has "ended" ?

4

1 回答 1

1

当用户离开页面时,您可以尝试使用 javascriptbeforeunload事件发送您的日志。如果使用 jQuery,代码如下所示:

$(window).bind("beforeunload",function(event) {
    //... put your ajax code here ...

    return "The log has sent to server.";
});

但是 beforeunload 事件将在您的屏幕上显示一个消息框。

此外,如果你想在另一个函数运行后运行一个函数,你可以使用 jQuery$.when()方法,如下所示:

$.when(functionOne(), functionTwo()).then(functionThree()).done(functionFour());

functionOne()、functionTwo()、functionThree() 和 functionFour() 必须是延迟对象。 这个博客简单解释了如何实现延迟对象。

于 2013-06-07T06:04:15.250 回答