
你的问题涉及到 Same Origin Policy(同源策略),这是一个关系到隐私和安全性的问题。任何浏览器都不会给你机会让你访问 **异域** 历史网址。
但是,如果这三个页面在同一域名下,你可以使用 Javascript 的 document.cookie 来记录每次访问的网址。
我写的例子需要4个文件,url_history.js,1.,2.,3.(三个 文件内容相同),代码写在空间(hi.baidu/keneks/item/50699e21f9300d0c72863e4d)
复制粘贴,将 url_history.js 和其它三个 文件放在一起,访问任何一个页面,点击任何链接,上面会自动显示曾经访问过的页面。
历史网址以 array 形式保存在 url_history 变量中,所以 url_history[0] 为上一个,url_history[1] 为上上一个,以此类推。
二、js中历史网页中怎么把上一个页面换成另一个页面
js是没有更改浏览历史url和获取从上一页开的url地址的,您可以使用window.location.replace(url);来重置浏览历史,
window.location.replace不在浏览器中保存跳转前的网址,因此按返回键将无效;
例子:
有 3个jsp页面(1.jsp, 2.jsp, 3.jsp),进系统默认的是1.jsp ,当我进入2.jsp的时候, 2.jsp里面用window.location.replace("3.jsp");与用window.location.href("3.jsp");从用户界面来看是没有什么区别的,但是当3.jsp页面有一个“返回”按钮,调用 window.history.go(-1)wondow.history.back();方法的时候,一点这个返回按钮就要返回2.jsp页面的话,区别就出来了,当用window.location.replace("3.jsp");连到3.jsp页面的话,3.jsp页面中的调用 window.history.go(-1)wondow.history.back();方法是不好用的,会返回到1.jsp 。当用window.location.href("3.jsp");连到3.jsp页面的话,3.jsp页面中的调用 window.history.go(-1)wondow.history.back();方法是好用的,会返回2.jsp。因为window.location.replace("3.jsp");是 不向服务器发送请求的跳转,而window.history.go(-1)wondow.history.back(); 方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面1.jsp 。window.location.href("3.jsp");是向服务 器发送请求的跳转,window.history.go(-1)wondow.history.back(); 方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到2.jsp。
三、JS或jQuery,清除网页历史记录在展示历史记录的页面添加如下js 。
<script type=text/javascript src=js/jquery.js></script>
<script type=text/javascript src=js/jquery.cookie.js></script>
<script type=text/javascript>
$(function{
var art_title = $("title").
var art_url = document.URL
var history
var json="["
//json1是第一次注入cookie以后的第一个json,"此时还不是数组" 以点带面的处理
var json1
var canAdd= true
//var json1=eval("({sitename:'dreamdu',sitedate:new Date(1980, 12, 17, 12, 0, 0)})")
if(!$.cookie("history")){
//第一次的时候需要初始化
history = $.cookie("history","{title:\""+art_title+"\""+",url:\""+art_url+"\"}")
}else {
//已经存在
history = $.cookie("history")
json1 = eval("("+history+")")
$(json1).each(function{
if(this.title==art_title){
canAdd=false
return false
}
})
if(canAdd){
$(json1).each(function{
json = json + "{\"title\":\""+this.title+"\",\"url\":\""+this.url+"\"},"
})
json = json + "{\"title\":\""+art_title+"\",\"url\":\""+art_url+"\"}]"
$.cookie("history",json,{expires:1})
}
}
})
</script>
在展示历史记录的页面添加如下js
<script type=text/javascript src=js/jquery.js></script>
<script type=text/javascript src=js/jquery.cookie.js></script>
<script type=text/javascript>
$(function{
if($.cookie("history")){
var json = eval("("+$.cookie("history")+")")
var list =""
$(json).each(function{
list = list + "<li><a href='"+this.url+"' target='_blank'>"+this.title+"</a></li>"
alert(this.url)
})
$("#list").(list)
}
})
</script>
</head>
01
打开IE浏览器,点击“设置”后,d出如下图所示的菜单项选择“Internet选项”,如下图红色方框标注所示。
02
点击“Internet选项”后,就打开如下图所示的“Internet选项”设置对话框,中间用红色方框标注的就是我们要设置的对象。
03
点击对话框中部的“删除”按钮,如下图红色方框标注所示。
04
点击删除按钮后,就打开如下图所示的删除项目对话框,按照如下图的设置进行设在,去掉第一个勾选,然后勾选下面其它所有项,最后点击右下角的“确定”按钮,这样IE就开始删除浏览记录了,若是很久没有删除IE浏览器的历史记录,那么时间可能会久一点,另外在删除IE浏览器记录时,最好关闭其它打开的IE浏览器网页,这样就可以确保删除“干净”。
05
在“Internet选项”的中部点击“设置”按钮,如下图红色方框标注所示,点设置后就打开如下图左边的“Internet 临时文件和历史记录设置”,可以将要使用的磁盘空间设置小一些,然后最下面的网页保存在历史记录中的天数改小,或者改为0,这样就可以不让IE浏览器保存历史记录了。
06
另外在“Internet选项”界面勾选“退出时删除浏览历史记录”,这样在我们关闭IE浏览器时就会自动帮我们删除历史浏览记录,不用我们手动去删除了从而减少我们的工作,也避免在忙碌的时候忘记删除浏览记录。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)