Prevent an open download window in chrome using a barcode reader

I have this problem with my website (MVC3, C #) and 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 in by the barcode reader and automatically sends the form, which with ajax fills the div with the list id =. My problem is that with chrome and i.e. After sending the text to Chrome, download windows appear, and the favorites window appears in ie. I suppose this is because the barcode reader inserts the text [CR] [LF] into the text and opens these windows. I thought the barcode reader was inserting ctrl-j at some point, because this combination opens the download window in chrome and favorites in ie, but with firefox the download window does not open (as well as ctrl-j).

I don’t want my client to set up a barcode reader for my page to work, so I want a solution in javascript to solve this problem.

thanks!!!

+6
source share
6 answers

I found this link, but the only solution was to change your standard scanner symbol ... I'm not sure I can change mine, although therefore, like you, I would look for a fix related to the browser. Maybe javascript. I will try to process the characters using javascript so that this does not happen ... if I have any success, I will try to remember to return here and tell you that he

I think this solves the problem ....

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

lemme knows if it works for you too. Make sure you also clear the cache ...

+5
source

this code works for me

 $(document).ready(function(){ $("#input").keydown(function(e){ if(e.which==17 || e.which==74 || e.keyCode == 13){ e.preventDefault(); } }) }); 
+1
source

My scanner (Intermec SR30) is configured to apply three new line characters after the barcode. I found this by opening Vim, pasting, and then browsing the barcode. Then I put the file in od -ax:

 0000000 3 1 2 2 1 0 9 9 9 4 8 5 2 8 nl nl 3133 3232 3031 3939 3439 3538 3832 0a0a 0000020 nl 000a 0000021 

I can capture 'nl with:

 $(document).ready(function(){ $("#barcode").keypress(function(e){ console.log('"' + e.keyCode + '"\n'); if(e.keyCode == 13){ e.preventDefault(); } }) }); 

but the window loading event (Ctrl + j from the keyboard) is deployed by the browser before it reaches the open page. This issue also affects Firefox 30.0.

0
source

The approved response code locks the CTRL and J keys. This would only lock CTRL + J

 $("#barcode").keypress(function(event){ if(event.keyCode == 74 && event.ctrlKey){ event.preventDefault(); } }); 
0
source

This code below does not work. Because if the barcode value has the character "J", you cannot get the correct result. We are trying to add an e.ctrlkey control, but this time only one barcode character will be recovered. Solving via js seems difficult. Perhaps the best option is to change the scanner settings.

 $(document).ready(function(){ $("#input").keydown(function(e){ if(e.which==17 || e.which==74 || e.keyCode == 13){ e.preventDefault(); } }) }); 
0
source

This works for me.

 <script> document.addEventListener('keydown', function(event) { if( event.keyCode == 13 || event.keyCode == 17 || event.keyCode == 74 ) event.preventDefault(); }); </script> 
0
source

Source: https://habr.com/ru/post/914345/


All Articles