mercredi 22 août 2018

How to capture iframe console output with jquery?

I'm trying to catch all types of console output from an iframe element. This is what I have, a slightly modernized version of Capture console.log messages of an iframe after navigation:

$.each(["log", "info", "debug", "warn", "error"], function (type) {
        var original = $("#result").contents().console[type];
        console.log("x");
        $("#result").contents().log[type] = function() {
            $("#console").append(arguments);
            original.apply($("#result").contents().console[type], arguments);
        };
});

#console is my div that should contain all the messages (for now), and #result is the iframe itself.

The problem is TypeError: undefined is not an object (evaluating '$("#result").contents().log')




Aucun commentaire:

Enregistrer un commentaire