注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发AJAX → 文章内容

AJAX:如何处理书签和后退按钮

作者:佚名 来源:不详 发布时间:2007-12-10 22:14:33
window.onload = initialize;
function initialize() {
 // initialize the DHTML History
 // framework
 dhtmlHistory.initialize();
 
 // subscribe to DHTML history change
 // events
 dhtmlHistory.addListener(historyChange);
   
 // 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 data";
  complexObject.value3 = new Array();
  complexObject.value3[0] = "array 1";
  complexObject.value3[1] = "array 2";
   
  dhtmlHistory.add("complexObject",
           complexObject);
          
  // cache some values in the history
  // storage
  debug("Storing key 'fakeXML' into "
     + "history storage", false);
  var fakeXML =
   '<?xml version="1.0" '
   +   'encoding="ISO-8859-1"?>'
   +   '<foobar>'
   +     '<foo-entry/>'
   +   '</foobar>';
  historyStorage.put("fakeXML", fakeXML);
 }

  然后,如果用户离开页面后又通过后退按钮返回该页面,我们可以使用get()方法提取保存的值,或者使用hasKey()方法检查该值是否存在。

window.onload = initialize;
function initialize() {
 // initialize the DHTML History
 // framework
 dhtmlHistory.initialize();
 
 // subscribe to DHTML history change
 // events
 dhtmlHistory.addListener(historyChange);
   
 // 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 data";
  complexObject.value3 = new Array();
  complexObject.value3[0] = "array 1";
  complexObject.value3[1] = "array 2";
   
  dhtmlHistory.add("complexObject",
           complexObject);
          
  // cache some values in the history
  // storage
  debug("Storing key 'fakeXML' into "
     + "history storage", false);
  var fakeXML =
   '<?xml version="1.0" '
   +   'encoding="ISO-8859-1"?>'
   +   '<foobar>'
   +     '<foo-entry/>'
   +   '</foobar>';
  historyStorage.put("fakeXML", fakeXML);
 }
 
 // retrieve our values from the history
 // storage
 var savedXML =
       historyStorage.get("fakeXML");
 savedXML = prettyPrintXml(savedXML);
 var hasKey =
      historyStorage.hasKey("fakeXML");
 var message =
  "historyStorage.hasKey('fakeXML')="
  + hasKey + "<br>"
  + "historyStorage.get('fakeXML')=<br>"
  + savedXML;
 debug(message, false);
}

  prettyPrintXml()是一个定义在完整示例源代码中的实用方法;此函数准备在web页面中显示以便用于调试的简单XML。


更多内容请看PCdog.com--Ajax技术专题
上一页  [1] [2] [3] [4] [5] [6] [7] [8]  下一页


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved