C#使用双链表来简单模拟IE前进后退功能
来源:互联网 发布:剑灵萝莉捏脸数据图 编辑:程序博客网 时间:2024/06/08 17:12
简单的测试了一下IE前进和后退的过程.
依次访问网站A,B,C,D.
后退至 B,
然后重新请求网站E,
则记录的保存顺序则是 A,B,E
C,D将会从记录列表中删除.
下面看代码(以下操作均在内存中进行):
一个History对象,用来生成一个记录对象,该对象包含 url,title,html三个属性.
class History
{
private string Title_ = "";
private string WmlSource_ = "";
private string Url_ = "";
public string Title
{
get { return Title_; }
set { Title_ = value; }
}
public string WmlSource
{
get { return WmlSource_; }
set { WmlSource_ = value; }
}
public string Url
{
get { return Url_; }
set { Url_ = value; }
}
public History()
{
}
public History(string t, string w, string u)
{
Title_ = t;
WmlSource_ = w;
Url_ = u;
}
}
HistoryAction是对链表操作静态类,具体看代码注释
class HistoryAction
{
//活动节点对象,即当前的节点对象
private static LinkedListNode<History> HistoryCurrentNode= null;
//全局的链表对象,所以记录均保存到该对象中
private static LinkedList<History> HistoryList = new LinkedList<History>();
//设置保存最大条数,当达到该条数时,每次增加记录时,均依次删除原有记录
private static int MaxList = 10;
/// <summary>
/// 或取当前的记录信息
/// </summary>
public static History CurrentHistory
{
get { return (History)HistoryCurrentNode.Value; }
}
/// <summary>
/// 当前后退时否可用,用于设置按钮状态信息
/// </summary>
public static bool IsBack
{
get
{
return HistoryCurrentNode.Next == null ? false : true;
}
}
/// <summary>
/// 当前前进时否可用,用于设置按钮状态信息
/// </summary>
public static bool IsGo
{
get
{
return HistoryCurrentNode.Previous == null ? false : true;
}
}
/// <summary>
/// 向历史记录链表中加入新的节点
/// </summary>
/// <param name="h"></param>
public static void Add(History h)
{
LinkedListNode<History> tem = HistoryList.First;
//如果连续加入url相同的记录,则只加入一次,可以根据自已情况设置
if (tem!=null && ((History)tem.Value).Url.ToLower() == h.Url.ToLower())
{
return;
}
//当当前节点不为空,或该节点的上一个节点也不为空时,则删除该节点的前所有节点(模拟IE)
//模拟IE对前进后退的处理
if (HistoryCurrentNode != null && HistoryCurrentNode.Previous != null)
{
DelNode(HistoryCurrentNode);
}
//处理限制最大记录条数
if (MaxList > 0)
{
if (HistoryList.Count + 1 > MaxList)
{
HistoryList.RemoveLast();
}
}
HistoryCurrentNode = new LinkedListNode<History>(h);
HistoryList.AddFirst(HistoryCurrentNode);
}
/// <summary>
/// 后退
/// </summary>
public static void Back()
{
HistoryCurrentNode = HistoryCurrentNode.Next;
}
/// <summary>
/// 前进
/// </summary>
public static void Go()
{
HistoryCurrentNode = HistoryCurrentNode.Previous;
}
/// <summary>
/// 删除指定节点前所有节点
/// </summary>
/// <param name="node"></param>
private static void DelNode(LinkedListNode<History> node)
{
while (node.Previous != null)
{
HistoryList.Remove(node.Previous);
}
}
}
页面调用方法
private void AddHistory(string title, string wmlsource, string url) //将记录加到列表中
{
History h = new History();
h.Title = title;
h.WmlSource = wmlsource;
h.Url = url;
HistoryAction.Add(h);
RefurbishGoBackButton(); //刷新按钮状态.由自已定义
}
private void Back() //后退
{
HistoryAction.Back();
History h = HistoryAction.CurrentHistory; //获取后退后的History对象
LoadHistory(h); //处理该对象,由自已定义.
RefurbishGoBackButton();//刷新按钮状态.由自已定义
}
private void Go() //前进
{
HistoryAction.Go();
History h = HistoryAction.CurrentHistory;
LoadHistory(h); //处理该对象,由自已定义.
RefurbishGoBackButton();//刷新按钮状态.由自已定义
}
OK,搞定,实际上非常简单,这里可以看到LinkedList的方便之处了.对性能的处理请自已把握.
好了,如果有不合理的地方请大家指正.
【Reprinted from http://www.cnblogs.com/hcl0208/archive/2009/04/18/1438641.html】
- C#使用双链表来简单模拟IE前进后退功能
- C#使用双链表来实现模拟IE前进后退功能
- html页面实现IE的前进、后退功能
- JAVA 类 IE浏览器前进、后退等功能操作
- HTML前进后退功能
- 考试系统--前进/后退功能
- 前进,返回,后退功能实现
- 使用jswing自制简单浏览器 实现浏览网络及本地资源 有前进,后退,刷新,文件新建等功能
- 使IE中的后退、前进按钮失效
- 使IE中的后退、前进按钮失效
- [数据结构]双链表模拟网站前进后退
- Python模拟浏览器前进后退操作
- 查看图片(前进后退)功能
- UIWebView的前进和后退功能
- H5 单页面解决“前进”,“后退”功能
- 使用history.pushState()和popstate事件实现AJAX的前进、后退功能
- 几种方法实现ajax请求内容时使用浏览器后退和前进功能
- 使用栈结构简易实现浏览器的后退与前进功能(以Android为例)
- STS
- 折腾(一)新硬盘和三系统
- 静态编译wxGTK选项!
- access和SQL语句的区别
- 虚函数专题
- C#使用双链表来简单模拟IE前进后退功能
- 要毕业了,论文写完了,无聊了
- 整理一下 sql 索引问题
- VMware Tools安装
- 程序学习--如何阅读别人的代码
- 不同之处?
- 为什么 Mozilla 要固守 Gecko 内核
- 《原创》数据库操作封装ORM
- CToolTipCtrl