19 thoughts on “Barcode reader”

I think it would be a great idea to incorporate barcode labels in to more everyday life. Have seen that the iphone has app’s that you can download to scan and compare prices of food online, as well as an app that tells you the content of the food. Great start, just hope they keep developing the idea!

The barcode reader invokes a URL, so the only way I know to populate the web form field is to use a back-end script as follows:

First the simplest way, make it the first field that the user can enter (wizard like):

start of with a page (let’s say start.html”) that just has a link that says “select barcode” or something that has the “pic2shop: link in (as in the example)

set the callback to point to your own script say:
pic2shop://scan?callback=http://www.yourdom.com/yourpath/dobarcode.php?barcode=EAN
where “dobarcode.php” is the name of your scrip (or dobar.py” if you do python, etc.

make the script dobarcode.php generate a web page with the form with the first barcode field already filled in with the barcode returned by pic2shop

Alternative a little more complex

create a script “form.php” that generates a form (say with fields barcode, page, comment). The script should also be readytyo accept parameters to pre-fill the various fields, so that: form.php?barcode=123456789&page=20&comment=hello+world would pre-populate the relevant fields

the form has a ‘choose’ barcode link (possibly only if there is no barcode given, or maybe just after it to change it)
However, instead of a direct link to pic2shop, the link should invoke some javascript on the web page. The script should take the content of any of the form fields except the one for the barcode, then generate a URL with them prefilled and the barcode one with barcode=EAN (for pic2shop) as before.

for example, if the user had already filled in the page number field with 42, but no comment, then the Javascript should create the url:
pic2shop://scan?callback=http://www.yourdom.com/yourpath/form.php?page=42&barcode=EAN
do remember to url encode the parameters *twice* once as you build the http://www.yourdom.com/ url, and oncde when you encode this URL to make ot the callback parameter for pic2shop

when pic2shop has scanned the barcode your form.php scriop will be called again, this time with the page and the barcode set, so the form would be ready of the remaining usre input

your form then has a standard submit button to do whatever you like with.

In the example the callback is to the same web page that it starts on, with just the barcode number displayed. However, the callback can be a different script, which can then do anything you want, for example, redirect to the Amazon page for the book (maybe after 13 to 10 character ISBN conversion).

Thanks Alan. If I understand you correctly, if the url is the same it will stay in the same tab but if it is different it will open a new tab (iPone Safari). My problem is that I’m using jQuery Mobile and the URL contains a # which seems to be causing a problem. I’ll do some experiments.

On desktop browser the JavaScript in two tabs would be able to ‘talk’ to each other by seeing each others variables as they come form the same domain. This should then mean that the new tab is be able to close the old one … but not sure how that works on iPhone Safari.