簡單的測試了一下IE前進和後退的過程
依次訪問網站A
後退至 B
然後重新請求網站E
則記錄的保存順序則是 A
C
下面看代碼(以下操作均在內存中進行):
一個History對象
Code
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
{
Title_ = t;
WmlSource_ = w;
Url_ = u;
}
}
HistoryAction是對鏈表操作靜態類
Code
class HistoryAction
{
//活動節點對象
private static LinkedListNode<History> HistoryCurrentNode= null;
//全局的鏈表對象
private static LinkedList<History> HistoryList = new LinkedList<History>();
//設置保存最大條數
private static int MaxList =
/**//// <summary>
/// 或取當前的記錄信息
/// </summary>
public static History CurrentHistory
{
get { return (History)HistoryCurrentNode
}
/**//// <summary>
/// 當前後退時否可用
/// </summary>
public static bool IsBack
{
get
{
return HistoryCurrentNode
}
}
/**//// <summary>
/// 當前前進時否可用
/// </summary>
public static bool IsGo
{
get
{
return HistoryCurrentNode
}
}
/**//// <summary>
/// 向歷史記錄鏈表中加入新的節點
/// </summary>
/// <param name=
public static void Add(History h)
{
LinkedListNode<History> tem = HistoryList
//如果連續加入url相同的記錄
if (tem!=null && ((History)tem
{
return;
}
//當當前節點不為空
//模擬IE對前進後退的處理
if (HistoryCurrentNode != null && HistoryCurrentNode
{
DelNode(HistoryCurrentNode);
}
//處理限制最大記錄條數
if (MaxList >
{
if (HistoryList
{
HistoryList
}
}
HistoryCurrentNode = new LinkedListNode<History>(h);
HistoryList
}
/**//// <summary>
/// 後退
/// </summary>
public static void Back()
{
HistoryCurrentNode = HistoryCurrentNode
}
/**//// <summary>
/// 前進
/// </summary>
public static void Go()
{
HistoryCurrentNode = HistoryCurrentNode
}
/**//// <summary>
/// 刪除指定節點前所有節點
/// </summary>
/// <param name=
private static void DelNode(LinkedListNode<History> node)
{
while (node
{
HistoryList
}
}
頁面調用方法
Code
private void AddHistory(string title
{
History h = new History();
h
h
h
HistoryAction
RefurbishGoBackButton(); //刷新按鈕狀態
}
private void Back() //後退
{
HistoryAction
History h = HistoryAction
LoadHistory(h); //處理該對象
RefurbishGoBackButton();//刷新按鈕狀態
}
private void Go() //前進
{
HistoryAction
History h = HistoryAction
LoadHistory(h); //處理該對象
RefurbishGoBackButton();//刷新按鈕狀態
}
OK
好了
From:http://tw.wingwit.com/Article/program/net/201311/12193.html