简体   繁体   English

检查文件是否已被js更改

[英]check if file has been changed with js

i have some code that has two iframes but connected to the same file but one has a auto refresher to get the newest change and i want my 'if' statement to execute when they are not the same but its not working, the if statement is not executing although one has more text than the other (changed) my code below, its simple.我有一些代码有两个 iframe 但连接到同一个文件,但一个有自动刷新器以获取最新更改,我希望我的“if”语句在它们不同但不起作用时执行,if 语句是没有执行,虽然一个比另一个有更多的文本(更改)我下面的代码,它很简单。

 var iframeContent = getElementById('frame1');
    
setTimeout(function () {

    var iframeContent1 = getElementById("frame");


  
        if(iframeContent1 !== iframeContent) {
        
      
        window.location.href= './';
        }
}, 3000);

use setInterval function instead of setTimeout function to check file content every 3 second like below given example.使用setInterval function 而不是setTimeout function 每 3 秒检查一次文件内容,如下例所示。

var iframeContent = getElementById('frame1');

setInterval(function () {

    var iframeContent1 = getElementById("frame");

    if (iframeContent1 !== iframeContent) {

        window.location.href= './';

    }

}, 3000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM