Firefox “window.event is undefined” error

后端 未结 7 1379
悲哀的现实
悲哀的现实 2020-12-03 11:38

I have this script:

function postBackByObject(e) {
   var o = window.event.srcElement || e.target;
   if (o.tagName == \"INPUT\" && o.type == \"check         


        
相关标签:
7条回答
  • 2020-12-03 12:18

    Attaching the event is a solution but there's an alternative one that could be helpful for other people facing the same problem, after a long search I found out that:

    Event object is only reconized by firefox if you send explicitly the 'event' from the function

    So the problem occurs because window.event is not recognized by Firefox, and the solution is to pass event to the function, your code will be :

    function postBackByObject(e) {
       var o = e.srcElement || e.target;
       if (o.tagName === "INPUT" && o.type === "checkbox") {
            __doPostBack("", "");
        }
    }
    

    And you can still call it in your inline HTML passing event as a parameter:

    onclick="postBackByObject(event);"
    
    0 讨论(0)
提交回复
热议问题