如何配合IE的地址栏记录用户操作历史

emu 2006-03-03 06:23:52
原文发表在 http://www.blogjava.net/emu/archive/2006/03/03/33518.html

Ajax七宗罪第五宗里面,作者讽刺Ajax需要一个“没有back和history的浏览器”。很讽刺吗?只是作者这么想罢了。至少要让Ajax应用支持Forward和Back,并不需要什么了不起的技术,我们也不需要这样的浏览器来改变用户习惯,事实上我们完全能做到让Forward和Back更酷。

这是一个示范页面:
index.htm <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> emu's ajax bac,/forward sample </TITLE>
<META NAME="Author" CONTENT="emu">
<META NAME="Keywords" CONTENT="ajax history">
<META NAME="Description" CONTENT="这个例子演示了如何不跳转页面而配合IE的前进、后退按钮记录用户交互历史">
</HEAD>
<BODY>

<textarea cols=80 rows=30 id=t onkeypress="checkSave()">请在此处输入</textarea>

<iframe name=historyFrame width=0 height=0 src="hiddenpage.htm?0#0"></iframe>
<SCRIPT LANGUAGE="JavaScript">
<!--
historyFrame.history.go(-999)
var maxHistory=100;
var historyList=[];
var historyOffset=0;
var timer;
function checkSave(){
if(timer)clearTimeout(timer);
timer=setTimeout(saveHistory,500);
}
function saveHistory(){
if(t.value==t.oldValue) return;
historyList[historyOffset]=t.oldValue;
historyOffset++;
historyList.length=historyOffset
t.oldValue=t.value;
var url = historyFrame.location.protocol+"//"+historyFrame.location.pathname+"?";
historyFrame.location=url+historyOffset+"#"+historyOffset;
t.focus();
}
function gotoHistory(n){
if(n<historyOffset){
historyList[historyOffset]=t.value;
}else if(n>historyOffset){
}else return;
historyOffset=n;
t.value=historyList[historyOffset];
t.focus();
}

window.onload=function(){
t.oldValue=t.value;
}

//-->
</SCRIPT>
</BODY>
</HTML>


需要一个简单的页面放在同一目录下面:
hiddenpage.htm
<HTML>
<BODY onload="gotoHistory()">
<SCRIPT>
function gotoHistory(){
parent.gotoHistory(location.search.substr(1))
}
</SCRIPT>
</BODY>
</HTML>

好了,打开index页面,在文本区域里面做一些输入,然后试试IE的前进和后退按钮能提供多酷的功能。

这个方法由emu的好朋友twinson首先提出来,以后我们就叫它twinson方法吧。

全部原码点击这里下载:http://www.blogjava.net/Files/emu/ajax%20history.zip
...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
emu 2006-03-06
  • 打赏
  • 举报
回复
嗯,果然是行家。
bookmark问题的解决要通过提供静态链接,和history的解决完全是两个方面。两个问题被摆到一起来置疑Ajax,只能说置疑Ajax的人并不明白在Ajax世界有些游戏规则已经不同从前了。
通过被你称为的query的技术,静态链接的提供并不为难,但是会造成静态页面重复加载的问题,确实我现在也还没有很好的解决方案。但是这个问题也不应该成为置疑Ajax的理由,因为在旧的Web模式下这些链接本来也是表现为不同的url需要被重复加载的,可以说Ajax也是受到旧模式的拖累。
hax 2006-03-03
  • 打赏
  • 举报
回复
这个方法有个缺陷,虽然解决了history问题,但是没有解决bookmark问题。
-------------------------------------------------------------------------------- 飞鸽传书 (IP Messenger) Ver2.06 Copyright (C) 1996-2004 SHIROUZU Hiroaki All Rights Reserved. -------------------------------------------------------------------------------- 目录: 1. 软件简介 2. 许可协议 3. 系统要求 4. 使用说明 5. 相关信息 6. 广域网设置(广播设置) 7. 补充 8. 支持 9. 更新历史 10. 感谢 ================================================================================ 重要说明: comctl32.dll(公共控件) 要求 4.71 或以上版本 更多信息请参见 "系统要求" ================================================================================ -------------------------------------------------------------------------------- 1. 软件简介 - IPMsg 是一款局域网内即时通信软件, 基于 TCP/IP(UDP). 可运行于多种操作平台(Win/Mac/UNIX/Java), 并实现跨平台信息交流. - 不需要服务器支持. - 支持文件/文件夹的传送 (2.00版以上) - 通讯数据采用 RSA/Blofish 加密 (2.00版以上) - 十分小巧, 简单易用, 而且你可以完全免费使用它 - 目前已有的版本包括: Win32, Win16, MacOS, MacOSX, X11, GTK, GNOME, Java 等, 并且公开源代码. 请查看以下地址以获得相关信息: http://www.ipmsg.org/ -------------------------------------------------------------------------------- 2. 许可协议 (BSD License) Copyright (c) 1996-2004 SHIROUZU Hiroaki All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the SHIROUZU Hiroaki nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRI

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧