You must Sign In to post a response.
  • Category: JavaScript

    Window.event is not working in firefox

    Hi I am calling below onload function from my aspx page. This code is working in IE but not in firefox. window.event is not working in firefox. So I want to make this code work in all browsers
    How can I modify it? Please help me on this.

    THank you.
  • #764367
    what error you got ? please post your code so that we can help you better to resolve the issue
    Generally firefox handles such event in different pattern
    Instead of using window.event, you should add a parameter to the function signature
    see below snippet

    function SearchName(txtObj,selObj,e)
    var keyPressed;
    keyPressed = window.event.keyCode; // IE
    keyPressed = e.which; // Firefox
    <input type="text" name="txt1" onKeyPress="SearchName(this,selList,event)" value="<Type To Search>" onClick="javascript:this.value='';" style="width:200px;">

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764373
    For key press event you may try to get the key code for key which you pressed.

    You can try the following code

    var keyCode = (window.Event) ? e.which : e.keyCode;
    if( keyCode == 13 ) // Check the key code
    // Your code

    By Nathan
    Direction is important than speed

  • #764395
    Hai Chinnari,
    Yes, sometimes the window.event might not work so for that you can attach the event of the particular control rather than using the window event.
    There could be many ways to do this based on the control you are using.
    Below are the few links I am providing which is having the work around with some code snippet to do it:

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments