One way I have gotten it to work is as follows:
Have a button (Scan Card)
Click the Scan Card button to have a popup window show up.
The popup window sets focus to a textbox with a width and height of 0px (setting display: hidden will throw security errors later)
Swipe the card
The input is put into the textbox
Create functions to parse the output that is put to the textbox (most cards have a predefined number of characters per line)
When the scan is complete (You will need to determine the condition at which you can say it is complete, x number of character per line) fill in the form in the parent window.
I have implemented this for a Canadian driver's license in an app. I am not allowed to share the code but can assure you it can be done.