Home > Web Front-end > JS Tutorial > Method to capture console.log() output in JS_javascript skills

Method to capture console.log() output in JS_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:03:32
Original
1342 people have browsed it

The example in this article describes the method of capturing console.log() output in JS. Share it with everyone for your reference. The specific analysis is as follows:

We know that console.log() can output information to the debugger for developers to view. But what if we want to get the output of console.log() in JS? In fact, it is not difficult. Just save the original console.log first and then replace it with another implementation. The code is as follows:

var lastLog;
console.oldLog = console.log;
console.log = function(str) {
  console.oldLog(str);
  lastLog = str;
} 
console.log("Hello, Neo");
document.write(lastLog);
Copy after login

At this time, "Hello, Neo" is saved in lastLog.

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template