首页 > 解决方案 > 如何防止 iframe 显示具有特殊类名的元素?

问题描述

我目前正在尝试在 iframe 中为我的客户显示 matomo 仪表板。iframe 中有一些我不想显示的元素。

这是我尝试过的:

function removeSegmentedLog(){
    var segmentedlog = document.getElementById('iframe').contentWindow.document.getElementsByClassName('actionSegmentVisitorLog');
    console.log(segmentedlog);
    for (let j = 0; j <= segmentedlog.length; j++) {
        document.getElementById('iframe').contentWindow.document.getElementsByClassName('actionSegmentVisitorLog')[j].remove();
        console.log('remove');
    }
}

该函数在 iframe 元素的 onload 时调用。

控制台有时会说没有元素,但它们就在那里。

有什么方法可以防止 iframe 显示任何类名为 'actionSegmentVisitorLog' 的元素?

标签: javascriptiframe

解决方案


推荐阅读