USB Barcode scanner opens browser's downloads page
Asked Answered
O

8

8

I'm trying to scan some barcode to textfield contained in my browser but it opens the downloads page in any browser (chrome, firefox, ie). I'm guessing that there is some input equivalent to CTRL + J that triggers the browser to open the download page.

Is anyone ran into this problem? Is there a way to pass it (assuming that I my clients can't change their scanner configuration neither the browser configuration)?

Thanks.

Openandshut answered 15/1, 2015 at 9:56 Comment(1)
You can try with Internet Explorer 11 or follow Mustafa Sabir answer, is ok for Manhattan SD313B.Discobolus
T
12

Although it is late to post an answer, I hope this helps someone in future.

The problem is due to the end character sent from the barcode reader. The default setting of my barcode reader is to send CR+LF after input. This unfortunately opens downloads page in chrome. The fix for this is very simple, instead of configuring the scanner itself (which can be tricky), you can add the following script to your page to ignore the end character sent from barcode scanner:

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

There was also an old bug opened for this with chrome, but this was closed/unresolved since this is not a bug but more of an input configuration issue.

Turino answered 23/1, 2017 at 11:33 Comment(0)
S
4

You have to setup your scanners.

Ctrl-J = 0x0A = Linefeed for Unix-like Systems

Check the manuels of your scanner-model for that. Normally you can find there some Barcodes which change your settings, otherway is to change your driver or you have settings in your driver for that.

Sanjuanitasank answered 15/1, 2015 at 10:30 Comment(3)
I prefer not to mess with the scanner settings because my clients might have different ones. Is there a way to avoid that by javascript code?Openandshut
no way. You have no access for that with JS and the scanners are missconfigurated for the target OSSanjuanitasank
Can you comment on scanner brands that you have seen provide this key remapping option? I have a Zebra DS9208 and its manual nor nothing I can find online shows any options to remap keycodes that are scanned such that they emit alternate keys to the keyboard.Lanza
C
2

Putting control like (event.keyCode == 13 || event.keyCode == 17 || event.keyCode == 74) won't fix problem. Because if barcode value has 'J' character in it, you wont be able to get barcode result truely. We try to add e.ctrlKey control extra. But this time we retrieve only one character from barcode. It seems that solving problem via js is hard. Maybe the best option is changing scanner settings.

Catnap answered 18/7, 2017 at 9:21 Comment(0)
D
2
//I managed to focus on exactly what was being sent by Chrome, and ignore just that:
var lastKeyCode = "";
document.addEventListener('keydown', function (event) {
    if (lastKeyCode == "ControlLeft" && event.code == "KeyJ")
        event.preventDefault();
    lastKeyCode = event.code;
});
Disadvantageous answered 13/7, 2019 at 10:3 Comment(0)
A
2

AutoControl Shortcut Manager for Google Chrome

Use this extension to disable any kind of shortcut keys for the browser and it is easy and responsive.

Once you add this chrome extension it will show you guys the tutorial.

Argus answered 17/12, 2020 at 6:24 Comment(0)
S
1

The problem can be solved by checking if e.ctrlKey true then we can ignore the keypress. If the Ctrl key is pressed the e.ctrlKey is true

<script>
let data = ''

window.onload = function () {
     window.document.body.addEventListener('keydown', function(event){
        if( event.keyCode == 13 || event.keyCode == 16 ||  event.keyCode == 17 ) {
                event.preventDefault();
                    return;
                }

                if(event.ctrlKey) {
                    event.preventDefault();
                    return;
                }

        data += event.key
        console.log(data)
    });
}
</script>

By using this code we can prevent chrome from navigating to Downloads Page.

Squeeze answered 13/3, 2018 at 8:31 Comment(0)
N
0

I have this issue with chrome only. Firefox focus goes to google search bar after the first successful shot. I have a Manhattan barcode reader. For now i managed using Web ( also known as epiphany) it is the only one it works but it is not a "common customer suggest"

Nester answered 9/5, 2015 at 13:22 Comment(2)
Hi. I solved this issue by ignoring the 'CTRL' key when getting a key-down event. I am checking whether the key that was pressed is CTRL and if it is I do nothing. The only problem with that solution is that the Copy-Paste and some other stuff the involves the CTRL key doesn't work in this text field component. In my case I didn't need them. Hope this helps.Openandshut
Hi, I "solved" programming the barcode to swhich from LF+ CR to CR only. It is a little pain to tell to customers but i works for now.Nester
B
0

I got it working on my side, my problem was barcode was doing barcodeNumbers control j enter. I dont want the control j as it opens up the firefox download window, and I need enter to enter it into barcode search, so I made a script to ignore control j. Make sure you test to check if it works on your side. I've only tested it for the last 10mins and its working, but needs to be monitored for longer to make sure all other barcodes dont have side affects.

<script>
// remove ctrl j from any input
let barcodeData = '';
document.addEventListener('keydown', function(event) {
  if (event.keyCode === 13) { // 13 = enter key
    // Process the barcode data when Enter is pressed
    // console.log('Barcode data:', barcodeData);
    barcodeData = ''; // Reset the barcode data
  } else if (event.ctrlKey && event.keyCode === 74) { // 74 = j key
    // Ignore Ctrl+J (keycode 10 line feed LF)
    event.preventDefault();
  } else {
    // Append the key to the barcode data
    barcodeData += event.key;
  }
});
</script>
Bireme answered 27/3 at 5:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.