如何处理书签和后退按钮

 如何处理书签和后退按钮

  本文将展示一个开源JavaScript库,该脚本库给AJAX应用程序带来了书签和后退按钮支持。在学习完这个教程后,开发人员将能够获得对一个AJAX问题的解决方案(甚至连Google Maps和Gmail现在都不提供该解决方案):一个强大的、可用的书签和后退前进功能,其操作行为如同其他的Web应用程序一样。

  本文将阐述目前AJAX应用程序在使用书签和后退按钮方面所面临的严重问题;展示Really Simple History(RSH)库——一个可以解决以上问题的开源框架,并提供几个运行中的例子。

  本文所展示的这个框架的主要发明分为两部分。首先是一个隐藏的HTML表单,用于缓存大量短期会话的客户端信息;这种缓存功能为页面导航提供了强大的支持。其次是超链接锚点和隐藏Iframe的组合,它们被嵌入后退和前进按钮,用来截获和记录浏览器的历史记录事件。以上两种技术都被包装在一个简单的JavaScript库中来简化开发。

问题
  书签和后退按钮在传统的多页面Web应用程序中运行得非常好。当用户浏览web站点的时候,其浏览器的地址栏记录随新的URL而更新,这些记录可以被粘贴到电子邮件或者书签中供以后使用。后退和前进按钮也可以正常操作,使用户可以在访问过的页面中向前或向后翻动。

  但是AJAX应用程序却不一样,它们是运行在单个Web页面中的复杂程序。浏览器并不是为这类程序而构建的——这类Web应用程序已经过时,它们在每次鼠标点击的时候都需要重新刷新整个页面。

  在这种类似于Gmail的AJAX软件中,浏览器的地址栏在用户选择功能和改变程序状态的时候保持不变,这使得无法在特定的应用程序视图中使用书签。此外,如果用户按下“后退”按钮来“撤销”上次的操作,他们会惊奇地发现,浏览器会完全离开该应用程序的Web页面。

解决方案
  开源RSH框架可以解决这些问题,它为AJAX应用程序提供了书签和控制后退、前进按钮的功能。RSH目前还处于Beta阶段,可以在Firefox 1.0、Netscape 7+、Internet Explorer 6+等浏览器上运行;目前还不支持Safari(有关说明,请参见我的文章“Coding in Paradise: Safari: No DHTML History Possible”)。

  目前有几个AJAX框架对书签和历史记录问题有所帮助;但这些框架目前都有几个由于实现而造成的重大Bug(有关详细信息,请参见“Coding in Paradise: AJAX History Libraries”)。此外,很多AJAX历史记录框架被绑定到较大的库上,例如Backbase和Dojo;这些框架为AJAX应用程序引入了完全不同的编程模型,迫使开发人员使用全新的方式来获得历史记录功能。

  相较之下,RSH是一个可以包含在现有AJAX系统中的简单模块。此外,RSH库采用了一些技术以避免产生影响其他历史记录框架的Bug。

  RSH框架由两个JavaScript类组成:DhtmlHistory和HistoryStorage。

  DhtmlHistory类为AJAX应用程序提供历史记录抽象。AJAX页面使用add()方法添加历史记录事件到浏览器,指定新的地址和相关的历史记录数据。DhtmlHistory类使用一个锚散列(如#new-location)更新浏览器当前的URL,同时把历史记录数据和该新URL关联。AJAX应用程序将自己注册为历史记录的监听器,当用户使用后退和前进按钮进行浏览时,历史记录事件被触发,为浏览器提供新的位置以及与add()调用一起保存的任何历史记录数据。

  第二个类:HistoryStorage,允许开发人员保存任意数量的已存历史记录数据。在普通Web页面中,当用户导航到一个新的web站点时,浏览器卸载并清除web页面上的所有应用程序和JavaScript状态;如果用户用后退按钮返回,所有的数据都丢失了。HistoryStorage类通过一个包含简单散列表方法(例如put()、get()、hasKey())的API来解决这类问题。上面的方法允许开发人员在用户离开Web页面之后保存任意数量的数据;当用户按后退按钮重新返回时,历史记录数据可以通过HistoryStorage类来访问。在内部,我们通过使用隐藏的表单字段来实现此功能,这是因为浏览器会自动保存表单字段中的值,甚至在用户离开Web页面的时候也如此。

例子
  让我们先从一个简单的例子开始。

  首先,任何需要使用RSH框架的页面都必须包含dhtmlHistory.js脚本:

Java代码 复制代码
  1. <!-- Load the Really Simple   
  2. History framework -->   
  3. <script type="text/javascript"  
  4. src="../../framework/dhtmlHistory.js">   
  5. </script>  
<!-- Load the Really Simple
History framework -->
<script type="text/javascript"
src="../../framework/dhtmlHistory.js">
</script>

  DHTML历史记录应用程序也必须在与AJAX Web页面相同的目录下包含blank.html文件;这个文件与RSH框架打包在一起,且对于Internet Explorer来说是必需的。顺便提一下,RSH使用一个隐藏Iframe来跟踪和添加Internet Explorer的历史记录变化;这个Iframe需要我们指定一个实际的文件位置才能正常工作,这就是blank.html。

  RSH框架创建了一个叫做dhtmlHistory的全局对象,这是操纵浏览器历史记录的入口点。使用dhtmlHistory的第一步是在Web页面加载完成后初始化dhtmlHistory对象:

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();  
window.onload = initialize;
function initialize() {
// initialize the DHTML History
// framework
dhtmlHistory.initialize();


  然后,开发人员使用dhtmlHistory.addListener()方法订阅历史记录变化事件。这个方法带有一个JavaScript回调函数,当DHTML历史记录变化事件发生时,该函数接收两个参数:新的页面位置以及任何可与该事件关联的可选历史记录数据:

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();   
  6. // subscribe to DHTML history change   
  7. // events   
  8. dhtmlHistory.addListener(historyChange);  
window.onload = initialize;
function initialize() {
// initialize the DHTML History
// framework
dhtmlHistory.initialize();
// subscribe to DHTML history change
// events
dhtmlHistory.addListener(historyChange);


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

Java代码 复制代码
  1. /** Our callback to receive history change  
  2. events. */  
  3. function historyChange(newLocation,   
  4. historyData) {   
  5. debug("A history change has occurred: "  
  6. "newLocation="+newLocation   
  7. ", historyData="+historyData,   
  8. true);   
  9. }  
/** 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值。

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();   
  6. // subscribe to DHTML history change   
  7. // events   
  8. dhtmlHistory.addListener(historyChange);   
  9. // if this is the first time we have   
  10. // loaded the page...   
  11. if (dhtmlHistory.isFirstLoad()) {   
  12. debug("Adding values to browser "  
  13. "history"false);   
  14. // start adding history   
  15. dhtmlHistory.add("helloworld",   
  16. "Hello World Data");   
  17. dhtmlHistory.add("foobar"33);   
  18. dhtmlHistory.add("boobah"true);   
  19. var complexObject = new Object();   
  20. complexObject.value1 =   
  21. "This is the first value";   
  22. complexObject.value2 =   
  23. "This is the second data";   
  24. complexObject.value3 = new Array();   
  25. complexObject.value3[0] = "array 1";   
  26. complexObject.value3[1] = "array 2";   
  27. dhtmlHistory.add("complexObject",   
  28. complexObject);  
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地址栏中看到如下的地址:

http://codinginparadise.org/my_ajax_app#helloworld
  然后用户可以将这个页面做成书签,如果以后用到这个书签,AJAX应用程序可以读取#helloworld值,并用它来初始化Web页面。散列后面的地址值是RSH框架可以透明编码和解码的URL地址。

  HistoryData非常有用,它保存比简单的URL更为复杂的AJAX地址变化状态。这是一个可选值,可以是任何JavaScript类型,例如Number、String或Object。使用该保存功能的一个例子是在一个富文本编辑器中保存所有文本(比如在用户离开当前页面时)。当用户再回到这个地址时,浏览器将会将该对象返回给历史记录变化监听器。

  开发人员可以为historyData提供带有嵌套对象和表示复杂状态的数组的完整JavaScript对象;JSON (JavaScript Object Notation)所支持的在历史记录数据中都支持,包括简单数据类型和null类型。然而,DOM对象以及可用脚本编写的浏览器对象(如XMLHttpRequest)不会被保存。请注意,historyData并不随书签一起保存,当浏览器关闭,浏览器缓存被清空,或者用户清除历史记录的时候,它就会消失。

  使用dhtmlHistory的最后一步是isFirstLoad()方法。在某些浏览器中,如果导航到一个Web页面,再跳转到另一个不同的页面,然后按“后退”按钮返回到起始的站点,第一页将完全重新加载,并触发onload事件。这样会对想要在第一次加载页面时用某种方式对其进行初始化(而其后则不使用这种方式重新加载该页面)的代码造成破坏。isFirstLoad()方法可以区分是第一次加载一个Web页面还是用户导航到保存在历史记录中的Web页面时触发的“假加载”事件。

  在示例代码中,我们只想在第一次加载页面的时候添加历史记录事件;如果用户在加载页面后按后退按钮返回该页面,我们就不想重新添加任何历史记录事件:

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();   
  6. // subscribe to DHTML history change   
  7. // events   
  8. dhtmlHistory.addListener(historyChange);   
  9. // if this is the first time we have   
  10. // loaded the page...   
  11. if (dhtmlHistory.isFirstLoad()) {   
  12. debug("Adding values to browser "  
  13. "history"false);   
  14. // start adding history   
  15. dhtmlHistory.add("helloworld",   
  16. "Hello World Data");   
  17. dhtmlHistory.add("foobar"33);   
  18. dhtmlHistory.add("boobah"true);   
  19. var complexObject = new Object();   
  20. complexObject.value1 =   
  21. "This is the first value";   
  22. complexObject.value2 =   
  23. "This is the second data";   
  24. complexObject.value3 = new Array();   
  25. complexObject.value3[0] = "array 1";   
  26. complexObject.value3[1] = "array 2";   
  27. dhtmlHistory.add("complexObject",   
  28. complexObject);  
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);

  让我们继续使用historyStorage类。类似于dhtmlHistory,historyStorage通过一个叫historyStorage的全局对象来公开它的功能。该对象有几个模拟散列的方法,比如put(keyName、keyValue)、get(keyName)和hasKey(keyName)。键名称必须是字符串,同时键值可以是复杂的JavaScript对象甚至是XML格式的字符串。在我们的源代码例子中,在第一次加载页面时,我们使用put()将简单的XML放入historyStorage:

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();   
  6. // subscribe to DHTML history change   
  7. // events   
  8. dhtmlHistory.addListener(historyChange);   
  9. // if this is the first time we have   
  10. // loaded the page...   
  11. if (dhtmlHistory.isFirstLoad()) {   
  12. debug("Adding values to browser "  
  13. "history"false);   
  14. // start adding history   
  15. dhtmlHistory.add("helloworld",   
  16. "Hello World Data");   
  17. dhtmlHistory.add("foobar"33);   
  18. dhtmlHistory.add("boobah"true);   
  19. var complexObject = new Object();   
  20. complexObject.value1 =   
  21. "This is the first value";   
  22. complexObject.value2 =   
  23. "This is the second data";   
  24. complexObject.value3 = new Array();   
  25. complexObject.value3[0] = "array 1";   
  26. complexObject.value3[1] = "array 2";   
  27. dhtmlHistory.add("complexObject",   
  28. complexObject);   
  29. // cache some values in the history   
  30. // storage   
  31. debug("Storing key 'fakeXML' into "  
  32. "history storage"false);   
  33. var fakeXML =   
  34. '<?xml version="1.0" '  
  35. +      'encoding="ISO-8859-1"?>'  
  36. +      '<foobar>'  
  37. +         '<foo-entry/>'  
  38. +      '</foobar>';   
  39. historyStorage.put("fakeXML", fakeXML);}  
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()方法检查该值是否存在。

Java代码 复制代码
  1. window.onload = initialize;   
  2. function initialize() {   
  3. // initialize the DHTML History   
  4. // framework   
  5. dhtmlHistory.initialize();   
  6. // subscribe to DHTML history change   
  7. // events   
  8. dhtmlHistory.addListener(historyChange);   
  9. // if this is the first time we have   
  10. // loaded the page...   
  11. if (dhtmlHistory.isFirstLoad()) {   
  12. debug("Adding values to browser "  
  13. "history"false);   
  14. // start adding history   
  15. dhtmlHistory.add("helloworld",   
  16. "Hello World Data");   
  17. dhtmlHistory.add("foobar"33);   
  18. dhtmlHistory.add("boobah"true);   
  19. var complexObject = new Object();   
  20. complexObject.value1 =   
  21. "This is the first value";   
  22. complexObject.value2 =   
  23. "This is the second data";   
  24. complexObject.value3 = new Array();   
  25. complexObject.value3[0] = "array 1";   
  26. complexObject.value3[1] = "array 2";   
  27. dhtmlHistory.add("complexObject",   
  28. complexObject);   
  29. // cache some values in the history   
  30. // storage   
  31. debug("Storing key 'fakeXML' into "  
  32. "history storage"false);   
  33. var fakeXML =   
  34. '<?xml version="1.0" '  
  35. +      'encoding="ISO-8859-1"?>'  
  36. +      '<foobar>'  
  37. +         '<foo-entry/>'  
  38. +      '</foobar>';   
  39. historyStorage.put("fakeXML", fakeXML);   
  40. }   
  41. // retrieve our values from the history   
  42. // storage   
  43. var savedXML =   
  44. historyStorage.get("fakeXML");   
  45. savedXML = prettyPrintXml(savedXML);   
  46. var hasKey =   
  47. historyStorage.hasKey("fakeXML");   
  48. var message =   
  49. "historyStorage.hasKey('fakeXML')="  
  50. + hasKey + "<br>"  
  51. "historyStorage.get('fakeXML')=<br>"  
  52. + savedXML;   
  53. debug(message, false);   
  54. }  
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。

  请注意,相关数据只在该页面的历史记录中进行持久化;如果浏览器被关闭,或者用户打开一个新窗口并再次键入AJAX应用程序的地址,则该历史记录数据对于新的Web页面不可用。历史记录数据只有在用到后退或前进按钮时才被持久化,当用户关闭浏览器或清空缓存的时候就会消失。如果想真正长期持久化,请参阅Ajax MAssive Storage System (AMASS)。

  我们的简单示例已经完成。您可以演示或下载完整源代码。

示例2:O'Reilly Mail
  我们的第二个例子是一个简单的AJAX电子邮件模拟应用程序的示例,即O'Reilly Mail,它类似于Gmail。O'Reilly Mail描述了如何使用dhtmlHistory类来控制浏览器的历史记录,以及如何使用historyStorage对象来缓存历史记录数据。

  O'Reilly Mail用户界面由两部分组成。在页面的左边是一个带有不同电子邮件文件夹和选项的菜单,例如收件箱、草稿箱等。当用户选择了一个菜单项(如收件箱),就用这个菜单项的内容更新右边的页面。在一个现实应用程序中,我们会远程获取并显示选择的信箱内容,不过在O'Reilly Mail中,我们只显示已选择的选项。

  O'Reilly Mail使用RSH框架向浏览器历史记录中添加菜单变化并更新地址栏,允许用户利用浏览器的后退和前进按钮为应用程序做收藏书签和跳到上次变化的菜单。

  我们添加一个特殊的菜单项——地址簿,以说明如何来使用historyStorage。地址簿是一个由联系人名称和邮件地址组成的JavaScript数组,在一个现实应用程序中,我们会从一台远程服务器取得这个数组。不过,在O'Reilly Mail中,我们在本地创建这个数组,添加几个名称和电子邮件地址,然后将其保存在historyStorage对象中。如果用户离开Web页面后又返回该页面,那么O'Reilly Mail应用程序将重新从缓存检索地址簿,而不是再次联系远程服务器。

  我们用initialize()方法保存和检索地址簿:

Java代码 复制代码
  1. /** Our function that initializes when the page  
  2. is finished loading. */  
  3. function initialize() {   
  4. // initialize the DHTML History framework   
  5. dhtmlHistory.initialize();   
  6. // add ourselves as a DHTML History listener   
  7. dhtmlHistory.addListener(handleHistoryChange);   
  8. // if we haven't retrieved the address book   
  9. // yet, grab it and then cache it into our   
  10. // history storage   
  11. if (window.addressBook == undefined) {   
  12. // Store the address book as a global   
  13. // object.   
  14. // In a real application we would remotely   
  15. // fetch this from a server in the   
  16. // background.   
  17. window.addressBook =   
  18. ["Brad Neuberg 'bkn3@columbia.edu'",   
  19. "John Doe 'johndoe@example.com'",   
  20. "Deanna Neuberg 'mom@mom.com'"];   
  21. // cache the address book so it exists   
  22. // even if the user leaves the page and   
  23. // then returns with the back button   
  24. historyStorage.put("addressBook",   
  25. addressBook);   
  26. }   
  27. else {   
  28. // fetch the cached address book from   
  29. // the history storage   
  30. window.addressBook =   
  31. historyStorage.get("addressBook");   
  32. }  
/** Our function that initializes when the page
is finished loading. */
function initialize() {
// initialize the DHTML History framework
dhtmlHistory.initialize();
// add ourselves as a DHTML History listener
dhtmlHistory.addListener(handleHistoryChange);
// if we haven't retrieved the address book
// yet, grab it and then cache it into our
// history storage
if (window.addressBook == undefined) {
// Store the address book as a global
// object.
// In a real application we would remotely
// fetch this from a server in the
// background.
window.addressBook =
["Brad Neuberg 'bkn3@columbia.edu'",
"John Doe 'johndoe@example.com'",
"Deanna Neuberg 'mom@mom.com'"];
// cache the address book so it exists
// even if the user leaves the page and
// then returns with the back button
historyStorage.put("addressBook",
addressBook);
}
else {
// fetch the cached address book from
// the history storage
window.addressBook =
historyStorage.get("addressBook");
}

  处理历史记录变化的代码也很简单。在下面的源代码中,无论用户按后退还是前进按钮,都将调用handleHistoryChange。使用O'Reilly Mail定义的displayLocation实用方法,我们可得到newLocation并使用它将我们的用户界面更新到正确的状态。

Java代码 复制代码
  1. /** Handles history change events. */  
  2. function handleHistoryChange(newLocation,   
  3. historyData) {   
  4. // if there is no location then display   
  5. // the default, which is the inbox   
  6. if (newLocation == "") {   
  7. newLocation = "section:inbox";   
  8. }   
  9. // extract the section to display from   
  10. // the location change; newLocation will   
  11. // begin with the word "section:"   
  12. newLocation =   
  13. newLocation.replace(/section\:/, "");   
  14. // update the browser to respond to this   
  15. // DHTML history change   
  16. displayLocation(newLocation, historyData);   
  17. }   
  18. /** Displays the given location in the  
  19. right-hand side content area. */  
  20. function displayLocation(newLocation,   
  21. sectionData) {   
  22. // get the menu element that was selected   
  23. var selectedElement =   
  24. document.getElementById(newLocation);   
  25. // clear out the old selected menu item   
  26. var menu = document.getElementById("menu");   
  27. for (var i = 0; i < menu.childNodes.length;   
  28. i++) {   
  29. var currentElement = menu.childNodes[i];   
  30. // see if this is a DOM Element node   
  31. if (currentElement.nodeType == 1) {   
  32. // clear any class name   
  33. currentElement.className = "";   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值