How do I dynamically change the content in an iframe using jquery?

后端 未结 3 1824
夕颜
夕颜 2020-11-30 21:47

I was wondering if it is possible to have a site with an iframe and some jquery code that changes the iframe content every 30 seconds. The content is in different webpages.<

3条回答
  •  囚心锁ツ
    2020-11-30 22:11

    var handle = setInterval(changeIframe, 30000);
    var sites = ["google.com", "yahoo.com"];
    var index = 0;
    
    function changeIframe() {
      $('#frame')[0].src = sites[index++];
      index = index >= sites.length ? 0 : index;
    }
    

提交回复
热议问题