简体   繁体   中英

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.

 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.

var iframeContent = getElementById('frame1');

setInterval(function () {

    var iframeContent1 = getElementById("frame");

    if (iframeContent1 !== iframeContent) {

        window.location.href= './';

    }

}, 3000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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