Skip to content

Commit

Permalink
Behavior Keepalive - Fixes #4904
Browse files Browse the repository at this point in the history
  • Loading branch information
Kubik-Rubik committed Jul 7, 2015
1 parent 72ac015 commit 257ecfb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libraries/cms/html/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,24 @@ public static function keepalive()
return;
}

$url = JUri::base(true) . '/index.php?option=com_ajax&format=json';
$life_time = JFactory::getConfig()->get('lifetime') * 60000;
$refresh_time = ($life_time <= 60000) ? 45000 : $life_time - 60000;

// The longest refresh period is one hour to prevent integer overflow.
if ($refresh_time > 3600000 || $refresh_time <= 0)
{
$refresh_time = 3600000;
}

$url = JUri::root(true) . '/index.php?option=com_ajax&format=json';

$script = 'window.setInterval(function(){';
$script .= 'var r;';
$script .= 'try{';
$script .= 'r=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")';
$script .= '}catch(e){}';
$script .= 'if(r){r.open("GET","' . $url . '",true);r.send(null)}';
$script .= '},45000);';
$script .= '},' . $refresh_time . ');';

JFactory::getDocument()->addScriptDeclaration($script);

Expand Down

0 comments on commit 257ecfb

Please sign in to comment.