想实现的功能:
在js.html当中重写函数:clickSb()
点击:http://www.56dnf.com.cn/ad.html当中的红色div弹出:我在本地
但我的思路不成功,请各位老师指点
//http://127.0.0.1/js.html内容如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body></body><iframe src="http://www.56dnf.com.cn/ad.html" ></iframe>
</html>
<script language="javascript">
function clickSb()
{
alert("我在本地");}
</script>
//http://www.56dnf.com.cn/ad.html内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title><script language="javascript">
function clickSb()
{
alert("我在远程");}</script>
</head>
<body>
<div onclick="clickSb()" "id="sb" style="width:100px; height:100px; background:red;"></div>
</body>
</html>

解决方案 »

  1.   

    后面的clickSb会覆盖前面的clickSb
      

  2.   

    try:
    //http://127.0.0.1/js.html内容如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body></body><iframe id="f1" src="http://www.56dnf.com.cn/ad.html" onload="on_load()"></iframe>
    </html>
    <script language="javascript">
    document.domain = "56dnf.com.cn";
    function on_load(){
    window.frames["f1"].clickSb = function()
    {
        alert("我在本地");
    };
    }
    </script>
    //http://www.56dnf.com.cn/ad.html内容如下:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title><script language="javascript">
    function clickSb()
    {
        alert("我在远程");}
    document.domain = "56dnf.com.cn";
    </script>
    </head>
    <body>
    <div onclick="clickSb()" "id="sb" style="width:100px; height:100px; background:red;"></div>
    </body>
    </html>
      

  3.   

    无法解决~~~除非你自己开发浏览器而且你那样写只是父页的clickSb函数而已,并非框架里面的clickSb函数
      

  4.   

    首先,楼主要明白重写的含义
    重写是指在同一页面,或者最后合并在一个页面
    比如:
    同一页面,下面的a最后弹出2:
    <script>
    function a(){
    alert(1);
    }
    function a(){
    alert(2);
    }
    </script>合并,就是在一个js文件里写一个函数
    然后在html里通过script src=js文件
    并在html里重写你这种写法是2个互不相干的页面,哪里来的重写一说?
      

  5.   

    赞成上面的说法!!要你那样的实现:it's impossible!!楼主去看看设计模式方面的书吧!!