解決firefox不支援window.event.returnValue = false

來源:互聯網
上載者:User
1.       Firefox中所有使用event相關的代碼無法使用.

event是IE封裝過的全域對象,控制所有事的事件,但是這個對象在Firefox中不存在,所以在Firefox中無法使用,特別是event.keyCode也是無法取得的。

解決方案:

下面這段JS重新封裝了EVENT對象,直接在頁面引用,原先的events代碼均可試用於Firefox:

<script>/*firefox----這段js重新封裝了event對象,經驗證可以在Firefox下支援。----*/    function __firefox(){        HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);        window.constructor.prototype.__defineGetter__("event", __window_event);        Event.prototype.__defineGetter__("srcElement", __event_srcElement);    }    function __element_style(){        return this.style;    }    function __window_event(){        return __window_event_constructor();    }    function __event_srcElement(){        return this.target;    }    function __window_event_constructor(){        if(document.all){            return window.event;        }        var _caller = __window_event_constructor.caller;        while(_caller!=null){            var _argument = _caller.arguments[0];            if(_argument){                var _temp = _argument.constructor;                if(_temp.toString().indexOf("Event")!=-1){                    return _argument;                }            }            _caller = _caller.caller;        }        return null;    }    if(window.addEventListener){        __firefox();    }    /*end firefox------------------------------------------------*/</script>


2.       event.returnValue = false無法使用

雖然重新封裝了event但是這個方法還是無法支援

解決方案:

調用event.returnValue = false時候使用以下方法:

function setReturnValueFalse(){      if(document.all)    {        window.event.returnValue = false;    }    else    {        event.preventDefault();    }}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.