注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-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);

  historyChange()方法很简单,该函数在用户导航到一个新位置后接收newLocation以及任何与该事件关联的可选historyData。

/** Our callback to receive history change
   events. */
function historyChange(newLocation,
            historyData) {
 debug("A history change has occurred: "
    + "newLocation="+newLocation
    + ", historyData="+historyData,
    true);
}

  上面用到的debug()方法是定义在示例源文件中的一个实用函数,它与完整示例打包在一起供下载。debug()只是用来将消息打印到Web页面上;第二个布尔型参数(在上述代码中值为true)控制是否在打印新的调试消息之前清除原有的全部消息。

  开发人员使用add()方法添加历史记录事件。添加历史记录事件涉及为历史记录变化指定一个新地址,例如edit:SomePage,以及提供一个和该事件一起保存的可选historyData值。

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);

  在add()被调用之后,新的地址将立即作为一个锚值(链接地址)显示在浏览器的URL地址栏中。例如,对地址为http://codinginparadise.org/my_ajax_app的AJAX Web页面调用dhtmlHistory.add("helloworld", "Hello World Data")之后,用户将会在其浏览器URL地址栏中看到如下的地址:


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


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