Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6694555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:06:55+00:00 2026-05-26T06:06:55+00:00

I have an iframe that I wanna update every 20 seconds. So basically, the

  • 0

I have an iframe that I wanna update every 20 seconds. So basically, the url of the iframe should change to a new one from the array and it refreshes, every 20 seconds but my code doesn’t seem to work.

var Uni = {
    init: function () {
        this.refresh();
    },

    refresh: function () {
        var urlArr = [
            'http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/',
            'http://stephendnicholas.com/archives/310',
            'http://msdn.microsoft.com/en-us/scriptjunkie/ff696765', 
            'http://www.jquery4u.com/jquery-functions/jquery-each-examples/'
        ],

        iframeSrc = document.querySelector('#uni iframe').src;

        for (var i = 0, max = urlArr.length; i < max; i++) {
            setInterval(function(){
                iframeSrc = urlArr[i];
            }, 20000);
        }   
    }
}

Uni.init();

HTML:

<body id="uni">
   <iframe src="http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/">
   You browser doesn't support iframes, please update it.
   </iframe>
</body>

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:06:56+00:00Added an answer on May 26, 2026 at 6:06 am

    Check the last line of your urlArr[] declaration:

    ], // <- the comma should be a semicolon!
    

    Thanks to @AndyE for the hint.

    Update: Solution + working fiddle

    var Uni = {
        interval_holder : false,
        urlArr : [],
    
        init: function (args) {
            if (args) {
                for (url in args) { this.addUrl(args[url]); }
            };
            this.refresh();
            this.interval_holder = setInterval('myuni.refresh()', 20000);
            return this;
        },
    
        refresh: function () {
            iframeObj = document.querySelector('#uni iframe');
            this.urlArr.unshift(iframeObj.src);
            iframeObj.src = this.urlArr.pop();
            return this;
        },
    
        stop : function () {
            clearInterval(this.interval_holder);
            return this;
        },
    
        addUrl : function(url) {
            this.urlArr.push(url);
            return this;
        },
    
        removeUrl : function(url) {
            this.urlArr.splice(this.urlArr.indexOf(url),1);
            return this;
        }
    };
    
    window.myuni = Uni.init([
        'http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/',
        'http://stephendnicholas.com/archives/310',
        'http://msdn.microsoft.com/en-us/scriptjunkie/ff696765', 
        'http://www.jquery4u.com/jquery-functions/jquery-each-examples/'
    ]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that has an iframe From one of the pages within
I have an IFRAME that should be filled with content from JavaScript. Had the
Basically I have an iframe loaded that is accessed from the parent whenever it
I have a iframe that i want to open pdf's into from a list
I have one iframe in my page and i'm submiting my form to that
Basically I have an IFRAME that contains a given page - I want to
Basically I have an IFRAME that displays a given page. I want to position
I have an iframe that I was formally creating using a url with some
I have an iframe that I use to display HTML pages published from Excel.
I have an iframe that contains a page that is constantly updating (basically a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.