Skip to content Skip to sidebar Skip to footer

How Can I Execute A External Js From Html Every 10 Min?

I have a HMTL which execute a external JS. The JS returns my Google Calender events. I want my calender to be updated automatically every 10minutes. The HTML looks like:

Solution 1:

Try to put formatGoogleCalendar.init() in a setInterval, like this :

setInterval(function(){
formatGoogleCalendar.init({
    calendarUrl: 'https://www.googleapis.com/calendar/v3/calendars/magic.kfs@gmx.de/events?key=AIzaSyDei0zrhHPHAtYc5x7vjdUmGaC3FlFnm1Y ',
    past: true,
    upcoming: true,
    sameDayTimes: true,
    pastTopN: 20,
    upcomingTopN: 4,
    recurringEvents: true,
    itemsTagName: 'ul',
    upcomingSelector: '#events-upcoming',
    pastSelector: '#events-past',
    upcomingHeading: '<div id="Termine" >Kommende Termine</div> ',
    pastHeading: '<p><h2 class="medium left">Vergangene Termine</h2></p>',
    format: ['*date*', ': ', '*summary*', ' &mdash; ', '*description*', ' in ', '*location*']

  });
}, 600000);

Solution 2:

Move your init into a function and call that function in the setInterval() every 10 minutes.

<script>functioncalendarInit(){

  formatGoogleCalendar.init({
    calendarUrl: 'https://www.googleapis.com/calendar/v3/calendars/magic.kfs@gmx.de/events?key=AIzaSyDei0zrhHPHAtYc5x7vjdUmGaC3FlFnm1Y ',
    past: true,
    upcoming: true,
    sameDayTimes: true,
    pastTopN: 20,
    upcomingTopN: 4,
    recurringEvents: true,
    itemsTagName: 'ul',
    upcomingSelector: '#events-upcoming',
    pastSelector: '#events-past',
    upcomingHeading: '<div id="Termine" >Kommende Termine</div> ',
    pastHeading: '<p><h2 class="medium left">Vergangene Termine</h2></p>',
    format: ['*date*', ': ', '*summary*', ' &mdash; ', '*description*', ' in ', '*location*']

  });
}

var cal = setInterval(calendarInit(), 10*60*1000);

Solution 3:

Well you can use

setInterval(function, delay)

delay is in milliseconds and function is the name of the function you want to call. Therefore, you need to wrap your content of js file within a function as

functioncallAgain()
{

var formatGoogleCalendar = (function() {
'use strict';
var config;
.
.
.

}

and then use the setInterval(callAgain, 5000) in the script part of your html file

Post a Comment for "How Can I Execute A External Js From Html Every 10 Min?"