<?php
namespace app\components;

class JsHelper{	

	//弹出警告
	public function alert($msg){
		echo '<script language="javascript">alert("'. $msg .'");</script>';
	}
	
	//返回上一页
	public function goback(){
		echo '<script language="javascript">window.history.back();</script>';
	}
	
	//打开新窗口
	public function openwindow($url){
		echo '<script language="javascript">window.open("'. $url .'");</script>';
	}
	
	//转向地址
	public function location($window, $url){
		echo '<script language="javascript">'. $window .'.location = "'. $url .'";</script>';
	}
	
	//定时转向地址
	public function timerlocation($window, $url, $seconds){
		echo '<script language="javascript">setTimeout(function (){'. $window .'.location="'. $url .'";}, '. $seconds*1000 .');</script>';
	}
	
	//关闭窗口
	public function closewindow(){
		echo '<script language="javascript">opener = null; window.open("","_self"); window.close();</script>';
	}

	//显示倒计时
	public function timercountdown($seconds){
		echo '<span id="timercountdownbox"></span>';
		echo '<script language="javascript">
		var elapsed = '. $seconds .'; 
		document.getElementById("timercountdownbox").innerHTML = elapsed; 
		var timercountdown = setInterval(function (){
			elapsed--; 
			document.getElementById("timercountdownbox").innerHTML = elapsed; 
			if(elapsed<=0){clearInterval(timercountdown);}
		}, 1000);
		</script>';
	}
	
}
?>