用prototype 重新定义下go试试看呢,我马上试试,呵呵,沙发

解决方案 »

  1.   

    但是直接点击后退按钮或者右键菜单里的后退是否会触发 history.go(-1) 代码的运行呢?不能触发,你的定制又有何意义?
      

  2.   

    <script language="JavaScript">
    <!--
    function h()
    {
    this.go=function(i)
    {
    alert(i);
    }
    }
    var history = new h();history.go(-1);
    //-->
    </script>
    这样是不是把其他的属性和方法给隐藏了啊?
      

  3.   

    重写alert函数
    <script language="javascript">
    <!--
    var winAlert = window.alert;
    window.alert = function( str )
    {
        winAlert("Error:" + str );
    }alert("hahahaha");
    //-->
    </script>
      

  4.   

    http://community.csdn.net/Expert/topic/4132/4132607.xml?temp=.1979486
      

  5.   

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

  6.   

    我试了
    alert(history.constructor)
    打出来的是undefine,这样应该不能用prototypeconstructor 属性是所有具有 prototype 的对象的成员
      

  7.   

    history.go = function(num)
    {
    }
    这样写不行
    history.prototype  也不对,放弃,等高人解决:-)
      

  8.   

    <SCRIPT LANGUAGE="JavaScript">
     
     var a =new Function("alert(1);");
     var b =new Function("alert(2);");
    var c=function(){ a();b();}
     c();
     </SCRIPT>
      

  9.   

    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()多少次了
      
    }
      

  10.   

    history.go(n) = new Function("history.go(" + n + ");alert('" + n+ "');");
      

  11.   

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

  12.   

    重写是成功了,但是右键菜单 或者系统菜单里的后退并没有触发 history.go(-1)
      

  13.   

    <SCRIPT LANGUAGE="JavaScript">
     var x=1;
     history.go= function()
    {  if(x==1)
      {
     x=x+1;
    history.go(-1)
    alert(1);
      }
    }
     history.go(-1);
     </SCRIPT>
    应该是这个吧。
      

  14.   

    狼的方法可以改进
    <SCRIPT LANGUAGE="JavaScript">
     var x=1;
     HBhistoryGo=history.go;
     history.go=function(n)
    {  
    alert("HB")
    return HBhistoryGo(n);
    }
     history.go(-1);
     </SCRIPT>
      

  15.   

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

  16.   

    再改动下,不要变量n
    <SCRIPT LANGUAGE="JavaScript">
     HBhistoryGo=history.go;
     history.go=function()
    {  
    alert("HB")
    return HBhistoryGo(arguments[0]);
    }
     history.go(-1);
     </SCRIPT>
      

  17.   

    直接点击后退按钮或者右键菜单里的后退是不会触发 history.go(-1) 代码的运行的?只有直接写 history.go() 这种调用时这些代码才被调用,所以定制的意义不大?
      

  18.   

    另:天外水火的写法最好,即添加了新的内容,又保持了原有的功能:
    <SCRIPT LANGUAGE="JavaScript">
    history._go = history.go;
    history.go=function(n)
    {  
        alert("mm");
        return history._go(n);
    }
     history.go(-1);
     </SCRIPT>
      

  19.   

    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>
      
     
    的代码不错,呵呵
      

  20.   

    照作了两个小例子
    有点问题:
    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>
      

  21.   

    长见识了,想不到代码还可以这样写:<SCRIPT LANGUAGE="JavaScript">
    history._go = history.go;
    history.go=function(n)
    {  
        alert("mm");
        return history._go(n);
    }
     history.go(-1);
     </SCRIPT>
      

  22.   

    又学到一个:
    <SCRIPT LANGUAGE="JavaScript">function s()
    {
    alert(arguments.length);
    }
    s("111","2222");
     </SCRIPT>嘿嘿
      

  23.   

    不知道上面的方法都试过了没有,
    我认为不只是重构函数,
    还得重构一下类,history这个类,