以下为引用的内容:
window.onload = initialize;
function initialize() {
// initialize the DHTML History
// framework
dhtmlHistory.initialize();
// subscribe to DHTML history change
// events
dhtmlHistory.initialize();
// if this is the first time we have
// loaded the page...
if (dhtmlHistory.isFirstLoad()) {
debug("Adding values to browser "
+ "history", false);
// start adding history
dhtmlHistory.add("helloworld",
"Hello World Data");
dhtmlHistory.add("foobar", 33);
dhtmlHistory.add("boobah", true);
var complexObject = new Object();
complexObject.value1 =
"This is the first value";
complexObject.value2 =
"This is the second value";
complexObject.value3 = new Array();
complexObject.value3 = new Array();
complexObject.value3[1] = ¡°array 2¡±;
dhtmlHistory.add("complexObject",
complexObject);
软件开发网
在add()执行后的同时,新的地址作为一个链接地址将显示在浏览器的URL地址栏中。比如:在AJAX网页中当前地址是: ,执行完: dhtmlHistory.add(“helloworld”,”Hello World Data”)后用户将会在浏览器URL地址栏中看到如下的地址:
软件开发网
这是用户可以给这个页面做收藏书签,如果用户后来用到这个书签的时候,AJAX应用程序可以读取到:#helloworld值并用它来初始化网页。RSH框架透明的对URL地址值进行编码和解码。
historyData 在保存比较复杂状态的时候很有用处。这是一个可选的值,他可以是JavaScript的任何类型,比如:数字,字符串,对象等。使用这个功能的一个例子是在一个网页字符编辑器中,如果用户离开当前网页。当用户回退时,浏览器将会把对象返回给历史浏览变动监听器。
开发者可以给historyData提供带有嵌套对象和用数组表示的复杂JavaScript对象。然而,DOM对象和浏览器支持的脚本对象 XMLHttpRequest,并不保存。注意:historyData 并不随书签一起持续化,当浏览器关闭,浏览器缓存被清除和用户清除历史记录的时候,他也就消失了。