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

来源: 作者: 2007-10-24 出处:pcdog.com

ajax  google  java  javascript  xml  
上一页 1 2 3 4 5 6 7 8 下一页 
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技术  AJAX应用实践专题
上一页 1 2 3 4 5 6 7 8 下一页 
上一篇:Ajax 学习笔记(二)
下一篇:关于AJAX一个简单的例子