承接上篇转载文章,
public class BMController : Controller
{
private DBContext db = new DBContext();
//IE窗体监控器
private IE_Watcher _ieWatcher = null;
public ActionResult Index()
{
//实例化对象,将窗体对象作为参数传入,为什么呢?
_ieWatcher = new IE_Watcher();//this
_ieWatcher.UrlText = new UrlHistory("c:\\urlhistory.txt");
//获取所有已打开的IE窗体
IList windows = _ieWatcher.GetOpenedWindows();
//IE_Item item=new IERefersh.IE_Item ();
foreach (SHDocVw.InternetExplorer ie in windows)
{
//在这里加入自定义对象哦!!!
if (ie.LocationURL == "http://localhost:64674/")
_ieWatcher.ListenWindow(new IE_Item(ie).IE);
}
return View(db.BMZD.ToList());
}
public ActionResult IsRefresh()
{
_ieWatcher = new IE_Watcher();//this
_ieWatcher.UrlText = new UrlHistory("c:\\urlhistory.txt");
string time = _ieWatcher.UrlText.ReadHistory();
DateTime st = DateTime.Parse(time);
TimeSpan tspan = DateTime.Now - st;
double second = tspan.TotalSeconds;
int Tag = 0;
if (second > 30)
Tag = 1;
return Content(Tag.ToString());
}
}
对应JS文件
var numberItem = -1;
function DisplayCreat() {
$.ajax({
type: "Get",
url: "/BM/IsRefresh",
data: "person=12",
async: false,
cache: false,
success: function (msg) {
if(msg=="1")//更新
window.location.reload();//重新加载页面
},
error: function (e) {
numberItem = 0;
}
});
}
setInterval(function () {
DisplayCreat();
}, 5000);