首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript 系统方法覆盖了,再调用有关问题

2013-09-06 
javascript系统方法覆盖了,再调用问题就是我 现在需要暂时 覆盖掉系统的方法window.showModalDialog()这样

javascript 系统方法覆盖了,再调用问题
就是我 现在需要暂时 覆盖掉系统的方法
window.showModalDialog()

这样子覆盖的:
window.showModalDialog = function({参数}){
    //我需要判断其中一个 参数 让我使用我覆盖了的系统方法 还是我自己写的方法
   if(pram1){
      //如果成立我要调用 系统的那个 
      window.showModelDialog(......);
   }else{
     //不成立 就调用自己写的代码
   }
}


就是在条件成立的时候  我需要再次调用 那个被我覆盖的 方法怎么做呢?


javascript function showModelDialog js系统方法覆盖
[解决办法]
用代理模式就行。参考下面

原理详见:http://stackoverflow.com/questions/1729501/javascript-overriding-alert

    <script type="text/javascript">
        (function() {
            var proxied = window.showModalDialog;
            window.showModalDialog = function() {
                if (true) {
                     return proxied.apply(this, arguments);
                }
                else {
                   alert("Do your works");
                }
            };
        })();

        window.showModalDialog("http://www.baidu.com", "", "dialogWidth=600px;dialogHeight=300px");
    </script>

热点排行
Bad Request.