I am trying to extract the content of the console and have it sent as a pop up using javascript. The reason for this is I have lots of information being written to the console but I am unable to read the console in a particular environment. I have attempted to follow the answer to this question but have gotten errors: Can I extend the console object (for rerouting the logging) in javascript?
Here is my code followed by the errors I have gotten:
<p id="output"></p>
<script>
console.log("asdf")
(function() {
var exLog = console.log;
console.log = function(msg) {
exLog.apply(this, arguments);
alert(msg);
}
})()
</script>
this is the error
Uncaught TypeError: console.log(...) is not a function
Thanks for the help
Thanks for getting rid of the errors, as I stated in the question my goal is to be able to read errors that occur while the program runs. here is an example of what I want:
<script>
function func(){
return y
}
(function() {
var exLog = console.log;
console.log = function(msg) {
exLog.apply(this, arguments);
alert(msg);
}
})()
func()
</script>
I want this to have the error that occurs to pop up
(the error is Uncaught ReferenceError: y is not defined)
thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…