如何在react.js页面中从iframe中删除控制台错误



你好吗。我已经将iframe添加到我的react.js页面中,它很有效,但我从iframe中得到了很多错误。这是我为避免控制台错误而制作的iframe组件,但不能正常工作

import React, { useEffect, useRef } from 'react'
export default function (props) {
let iframeRef = useRef(null)
useEffect(() => {
const iframecurrent = iframeRef.current
iframecurrent.contentWindow.console.log = function() { /* nop */ };
}, [])
return <iframe {...props} ref={iframeRef} />
}

这个问题有什么解决办法吗?感谢

这可能是一个愚蠢的答案,但您是否尝试过覆盖console.error方法而不是console.log

useEffect(() => {
const iframecurrent = iframeRef.current
iframecurrent.contentWindow.console.error = function() { /* nop */ };
}, [])

最新更新