如何使用jQuery捕获iframe控制台输出?

时间:2018-08-22 17:59:00

标签: javascript jquery web iframe

我正在尝试从iframe元素捕获所有类型的控制台输出。这就是我所拥有的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是我的div,应该包含所有消息(目前),而#result是iframe本身。

问题是TypeError: undefined is not an object (evaluating '$("#result").contents().log')

0 个答案:

没有答案