我在某种重要的最新网站上工作。为此,当用户从另一个选项卡切换到带有网站的选项卡时,我需要刷新页面。
有没有办法用JavaScript / jQuery做到这一点?我知道public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Timetable']))
{
$model->attributes=$_POST['Timetable'];
$model->School_Id=Yii::app()->session['Schoolid'];
$CourseId=$_POST['CourseId'];
if($CourseId=="empty")
$model->CourseId='';
else
$model->CourseId=$_POST['CourseId'];
$model->Status=1;
if($model->save())
$this->redirect(array('view','id'=>$model->Id));
}
$this->render('update',array(
'model'=>$model,
));
}
用于刷新页面,但是当标签再次变为活动状态时(我只知道一次),我不知道如何告诉JavaScript执行此操作。
答案 0 :(得分:8)
您可以使用:
var vis = (function(){
var stateKey, eventKey, keys = {
hidden: "visibilitychange",
webkitHidden: "webkitvisibilitychange",
mozHidden: "mozvisibilitychange",
msHidden: "msvisibilitychange"
};
for (stateKey in keys) {
if (stateKey in document) {
eventKey = keys[stateKey];
break;
}
}
return function(c) {
if (c) document.addEventListener(eventKey, c);
return !document[stateKey];
}
})();
用法:
var visible = vis(); // gives current state
vis(aFunction); // registers a handler for visibility changes`
vis(function(){
document.title = vis() ? 'Visible' : 'Not visible';
});
你可以在这里读到: