1

I am 99% sure this isn't possible but I'll ask just incase someone has an idea.

A little background:

My users use a barcode scanner to consign items off the system. Each barcode is an ID number preceded with a "^" (so the system can tell if someone is scanning rather than just typing). As they scan each barcode the page automatically downloads a PDF (into an iframe) which is printed onto a label and stuck on the box. Then they move onto next and the next etc.

The automatic printing is handled with an onkeypress event attached to the document. This is the called function:-

function quickEntry() {
    if (String.fromCharCode(event.keyCode) == "^") {
        if (!scanning) {
            grn = '';
            scanning = true;
            setTimeout('addBarcode()', 1000);
        }
        else {
            alert("Still processing previous GRN.");
        }
    }
    else
        grn += String.fromCharCode(event.keyCode);
}

The Problem:

The problem is that after printing the first label the user needs to click on an area of the main html document before they can scan a barcode again even though the window itself still has focus.

Edit

Anyone arriving on this question take a look at this question for more up-to-date answers.

Community
  • 1
  • 1
John C
  • 3,052
  • 3
  • 34
  • 47

1 Answers1

2

My guess is that the window has focus but the input element has lost focus (focus has probably moved to the iframe or some element inside of it).

To find out which element has stolen your focus, you can use document.activeElement and change it's CSS style to make it stand out more or use CSS and the :focus selector.

To solve your problem, print the iframe with JavaScript and then force the focus back on the input element.

This might involve JavaScript calls between the main page and the iframe; there are answers on this site how to do that.

[EDIT] There are several ways to embed PDF into a web page. When you use an iframe, the PDF plugin will take control of the browser window (so it can respond to keyboard and mouse events).

Try to load the PDF with <object> (pdfobject.com/markup/index.php) instead of using an iframe

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • This doesn't seem to work. The iframe does not contain a html document (it contains the opened pdf) so javascript communication between the two pages is not possible. Using `document.activeElement` tells me that an appropriate element has focus (the onkeypress event is attached to the document rather than any particular element within it) however the event is not fired once the first pdf has been loaded. – John C Nov 12 '12 at 10:01
  • I fear that the embedded PDF viewer steals the focus :-/ Can you try to load the PDF with `` (http://pdfobject.com/markup/index.php) instead of using an `iframe`? – Aaron Digulla Nov 12 '12 at 11:38
  • Excellent, putting the PDF into an object was the key! Thanks – John C Nov 12 '12 at 14:22