<html>
<script>
  function checkIframeContent() {
    var iframe = document.getElementById('infrm');
    var iframeContent = iframe.contentDocument.documentElement.innerText;
    var forbiddenWords = ['代理', '验证', '网站']; // 违规词列表
<pre><code>for (var i = 0; i &lt; forbiddenWords.length; i++) {
  if (iframeContent.includes(forbiddenWords[i])) {
    window.location.href = 'http://qq.com'; // 违规词存在,跳转到指定网址
    break;
  }
}
</code></pre>
<p>}
</script></p>
<body style='margin:0;padding:0;height:100%' scroll=no>
  <iframe id='infrm' name='infrm' marginwidth='0' marginheight='0' width='100%' scrolling=auto src='http://auth.9a18.cn' frameborder='0' height='100%' allowfullscreen='true' onload='checkIframeContent()'></iframe>
</body>
</html>
<p>在上述代码中,我们定义了一个<code>checkIframeContent</code>函数,用于检测iframe展示的网址内容是否包含违规词。在iframe加载完成后,通过<code>onload</code>事件触发该函数。函数首先获取iframe的内容,然后遍历违规词列表,如果内容中包含任意一个违规词,就会执行跳转操作,将页面重定向到'http://qq.com'网址。</p>
<p>注意:由于涉及到跨域问题,如果iframe展示的网址与当前页面的域名不一致,可能会受到同源策略的限制,导致获取不到iframe的内容。在实际应用中,你可能需要采取其他方式来解决这个问题。</p>
JavaScript 检测 iframe 内容并跳转:防范违规词

原文地址: http://www.cveoy.top/t/topic/qzGV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录