Solution Firefox does not support Window.event.returnValue = False

Source: Internet
Author: User
1. All code in Firefox that uses event-related is not available.

Event is the global object that IE encapsulates, control all events, but this object does not exist in Firefox, so it cannot be used in Firefox, especially Event.keycode is also unable to obtain.

Workaround:

The following JS encapsulates the event object, directly in the page reference, the original events code can be tried in Firefox:

<script>/*firefox----This JS encapsulates the event object and is validated to be supported under 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 cannot be used

Although the event was encapsulated, this method is still not supported.

Workaround:

When calling Event.returnvalue = False, use the following methods:

function Setreturnvaluefalse ()

{  

    if (document.all)

    {

        window.event.returnValue = false;

    }

    else

    {

        event.preventdefault ();

    }

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.