300分,怎样用JS为history.go(-1); 添加自己的方法? 用prototype 重新定义下go试试看呢,我马上试试,呵呵,沙发 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 但是直接点击后退按钮或者右键菜单里的后退是否会触发 history.go(-1) 代码的运行呢?不能触发,你的定制又有何意义? <script language="JavaScript"><!--function h(){ this.go=function(i) { alert(i); }}var history = new h();history.go(-1);//--></script>这样是不是把其他的属性和方法给隐藏了啊? 重写alert函数<script language="javascript"><!--var winAlert = window.alert;window.alert = function( str ){ winAlert("Error:" + str );}alert("hahahaha");//--></script> http://community.csdn.net/Expert/topic/4132/4132607.xml?temp=.1979486 history.go = function(n) //把它修改了,但应该保存它原有的功能呀。{ alert("meizz"); switch(n) { case -1: history.back(); break; case 0 : location.href=location.href; break; case 1 : history.forward(); break; }} 我试了alert(history.constructor)打出来的是undefine,这样应该不能用prototypeconstructor 属性是所有具有 prototype 的对象的成员 history.go = function(num){}这样写不行history.prototype 也不对,放弃,等高人解决:-) <SCRIPT LANGUAGE="JavaScript"> var a =new Function("alert(1);"); var b =new Function("alert(2);");var c=function(){ a();b();} c(); </SCRIPT> history.go = function(n) //把它修改了,但应该保存它原有的功能呀。{ alert("meizz"); switch(n) { case -1: history.back(); break; case 0 : location.href=location.href; break; case 1 : history.forward(); break; }}这样写也不对,go是支持多个页面的history.go = function(n) //把它修改了,但应该保存它原有的功能呀。{ alert("meizz"); /// history.go(n); /// 这样导致死循环 //只可以 用循环来控制 history.back() 多少次 和 history.forward()多少次了 } history.go(n) = new Function("history.go(" + n + ");alert('" + n+ "');"); <SCRIPT LANGUAGE="JavaScript"> var x=1; history.go= function(){ if(x==1) { x=x+1; history.go(-1) alert(1); }} history.go(-1);//要是不加x作为判断,就无限递归,死循环了。 </SCRIPT> 重写是成功了,但是右键菜单 或者系统菜单里的后退并没有触发 history.go(-1) <SCRIPT LANGUAGE="JavaScript"> var x=1; history.go= function(){ if(x==1) { x=x+1; history.go(-1) alert(1); }} history.go(-1); </SCRIPT>应该是这个吧。 狼的方法可以改进<SCRIPT LANGUAGE="JavaScript"> var x=1; HBhistoryGo=history.go; history.go=function(n){ alert("HB") return HBhistoryGo(n);} history.go(-1); </SCRIPT> <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title></head><body><script type="text/javascript">var i=0;function history.go(n){ if(i == 1) return; i++; alert(n); if(n<=0) history.back(n); else history.forward(n);}</script><input type="button" value="test" onClick="history.go(-1)"></body></html> 再改动下,不要变量n<SCRIPT LANGUAGE="JavaScript"> HBhistoryGo=history.go; history.go=function(){ alert("HB") return HBhistoryGo(arguments[0]);} history.go(-1); </SCRIPT> 直接点击后退按钮或者右键菜单里的后退是不会触发 history.go(-1) 代码的运行的?只有直接写 history.go() 这种调用时这些代码才被调用,所以定制的意义不大? 另:天外水火的写法最好,即添加了新的内容,又保持了原有的功能:<SCRIPT LANGUAGE="JavaScript">history._go = history.go;history.go=function(n){ alert("mm"); return history._go(n);} history.go(-1); </SCRIPT> hbhbhbhbhb1021(天外水火(我要多努力)) ( ) 信誉:100 2006-03-17 13:47:00 得分: 0 再改动下,不要变量n<SCRIPT LANGUAGE="JavaScript"> HBhistoryGo=history.go; history.go=function(){ alert("HB") return HBhistoryGo(arguments[0]);} history.go(-1); </SCRIPT> 的代码不错,呵呵 照作了两个小例子有点问题:1:将history.go(-1)放在了函数内部,第一次可以正确执行,也就是可以倒退并alert("mm"); 第二次点aaa.html的连接进入eeee.htm,不可以倒退但能alert("mm");history._go = history.go;history.go=function(n){ alert("mm"); return history._go(n); history.go(-1);}2:将history.go(-1)放在了函数外部,好像不能执行倒退!history._go = history.go;history.go=function(n){ alert("mm"); return history._go(n); }history.go(-1);///////////////////////////////////aaa.htm<HTML><A HREF="eeee.htm">Excample</A></BODY></HTML>//eeee.htm<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title></head><body><script type="text/javascript">history._go = history.go;history.go=function(n){ alert("mm"); return history._go(n); history.go(-1);}//history.go(-1);</script><input type="button" value="test" onClick="history.go(-1)" ID=Button1></body></html> 长见识了,想不到代码还可以这样写:<SCRIPT LANGUAGE="JavaScript">history._go = history.go;history.go=function(n){ alert("mm"); return history._go(n);} history.go(-1); </SCRIPT> 又学到一个:<SCRIPT LANGUAGE="JavaScript">function s(){ alert(arguments.length);}s("111","2222"); </SCRIPT>嘿嘿 不知道上面的方法都试过了没有,我认为不只是重构函数,还得重构一下类,history这个类, asp.net页面中js如何通过$.post调用ashx文件 点击日历里面日期跳转到另一个页面,怎么不行,求解 要急疯了,大侠救我! 利用javascript怎样打开一个应用程序,比如说记事本? 求救,Script 中控制html控件的位置 【闭包问题】 大侠请教个问题关于父子窗口的 讨教! 判断输入为数字!求救! 请教高手,谢谢 为什么window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)无效? 为什么‘确认删除’的JavaScript代码不起作用?
<!--
function h()
{
this.go=function(i)
{
alert(i);
}
}
var history = new h();history.go(-1);
//-->
</script>
这样是不是把其他的属性和方法给隐藏了啊?
<script language="javascript">
<!--
var winAlert = window.alert;
window.alert = function( str )
{
winAlert("Error:" + str );
}alert("hahahaha");
//-->
</script>
{
alert("meizz");
switch(n)
{
case -1: history.back(); break;
case 0 : location.href=location.href; break;
case 1 : history.forward(); break;
}
}
alert(history.constructor)
打出来的是undefine,这样应该不能用prototypeconstructor 属性是所有具有 prototype 的对象的成员
{
}
这样写不行
history.prototype 也不对,放弃,等高人解决:-)
var a =new Function("alert(1);");
var b =new Function("alert(2);");
var c=function(){ a();b();}
c();
</SCRIPT>
{
alert("meizz");
switch(n)
{
case -1: history.back(); break;
case 0 : location.href=location.href; break;
case 1 : history.forward(); break;
}
}
这样写也不对,go是支持多个页面的
history.go = function(n) //把它修改了,但应该保存它原有的功能呀。
{
alert("meizz");
/// history.go(n); /// 这样导致死循环
//只可以 用循环来控制 history.back() 多少次 和 history.forward()多少次了
}
var x=1;
history.go= function()
{ if(x==1)
{
x=x+1;
history.go(-1)
alert(1);
}
}
history.go(-1);
//要是不加x作为判断,就无限递归,死循环了。
</SCRIPT>
var x=1;
history.go= function()
{ if(x==1)
{
x=x+1;
history.go(-1)
alert(1);
}
}
history.go(-1);
</SCRIPT>
应该是这个吧。
<SCRIPT LANGUAGE="JavaScript">
var x=1;
HBhistoryGo=history.go;
history.go=function(n)
{
alert("HB")
return HBhistoryGo(n);
}
history.go(-1);
</SCRIPT>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head><body>
<script type="text/javascript">
var i=0;
function history.go(n){
if(i == 1) return;
i++;
alert(n);
if(n<=0) history.back(n);
else history.forward(n);
}
</script>
<input type="button" value="test" onClick="history.go(-1)">
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
HBhistoryGo=history.go;
history.go=function()
{
alert("HB")
return HBhistoryGo(arguments[0]);
}
history.go(-1);
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
history._go = history.go;
history.go=function(n)
{
alert("mm");
return history._go(n);
}
history.go(-1);
</SCRIPT>
再改动下,不要变量n
<SCRIPT LANGUAGE="JavaScript">
HBhistoryGo=history.go;
history.go=function()
{
alert("HB")
return HBhistoryGo(arguments[0]);
}
history.go(-1);
</SCRIPT>
的代码不错,呵呵
有点问题:
1:将history.go(-1)放在了函数内部,第一次可以正确执行,也就是可以倒退并alert("mm");
第二次点aaa.html的连接进入eeee.htm,不可以倒退但能alert("mm");
history._go = history.go;
history.go=function(n)
{
alert("mm");
return history._go(n);
history.go(-1);
}2:将history.go(-1)放在了函数外部,好像不能执行倒退!
history._go = history.go;
history.go=function(n)
{
alert("mm");
return history._go(n);
}
history.go(-1);
///////////////////////////////////aaa.htm
<HTML>
<A HREF="eeee.htm">Excample</A>
</BODY>
</HTML>
//eeee.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head><body>
<script type="text/javascript">
history._go = history.go;
history.go=function(n)
{
alert("mm");
return history._go(n);
history.go(-1);
}
//history.go(-1);</script>
<input type="button" value="test" onClick="history.go(-1)" ID=Button1>
</body>
</html>
history._go = history.go;
history.go=function(n)
{
alert("mm");
return history._go(n);
}
history.go(-1);
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">function s()
{
alert(arguments.length);
}
s("111","2222");
</SCRIPT>嘿嘿
我认为不只是重构函数,
还得重构一下类,history这个类,