Search code examples
javascriptbarcode-scanner

Prevent open downloads window in chrome with barcode reader


i have this problem with my website (MVC3, C#) and a barcode reader. In my form i have something like this:

<ajax form....>

<input type=text />

<div id=list>
</div>

</form>

And the input is filled with a barcode reader and automatically submits the form that with ajax, fills the div with the id = list. My problem is that with chrome and ie, after the text is submited, a downloads windows appears in chrome and the favorites window appears in ie. I suppose that is because the barcode reader insers a [CR][LF] in the text and that opens those windows. I thought that the barcode reader was inserting a ctrl-j in some moment because that combination opens the downloads window in chrome and the favorites in ie, but with firefox the downloads window doesnt open (and is also ctrl-j).

I dont want to tell my client to configure the barcode reader so my page works, so i want a sollution in javascript maybe that fixes that problem.

thanks!!!


Solution

  • i found this link but the only solution was to change your scanner's default character... i'm not sure I can change mine though so , like you, I'd be looking for a browser-related fix too.. maybe javascript. i'll try handling the characters with javascript to prevent that from happening... if I have any success i'll try and remember to come back here and tell you hehehehehe

    i think this solves the issue....

    $(document).ready(function(){
        $("#input").keydown(function(e){
            if(e.which==17 || e.which==74){
                e.preventDefault();
            }else{
                console.log(e.which);
            }
        })
    });
    

    lemme know whether his works for you too.. make sure you empty the cache too...