

The barcode scanner still works completely locally in the user's browser. The only difference is that the "datasymbol-sdk-hlp.min.js" and "datasymbol-sdk.wasm" files necessary for the scanner to work will not be downloaded from your site, but from ours.
The scanner will be displayed in a separate HTML iframe tag, this makes it possible to isolate the scanner code from your site code, i.e. the scanner will not affect your site, its design, etc. in any way.
OnLine Test 1 OnLine Test 2
So what does it take to embed a "Hosted Barcode Scanner" into your website?

https://websdk.datasymbol.com
If your site does not support HTTPS, then the scanner will not work.

If you are proficient in HTML/JavaScript you can modify this code however you like.<script id='DataSymbolScript'> const viewWidth = 320; const viewHeight = 240; var leftPos = 0; var topPos = 0; const xAlign = 'none'; //none, left, right, float const yAlign = 'none'; //none, top, bottom, float const alignGap = 10; const opacity = 1.0; const addFrameStyle = ''; //additional style settings, for example: 'border: solid 2px #fff;' const sWebSDKKey = ''; var scannerSettings = { camera: { resx: 640, resy: 480, }, barcode: { barcodeTypes: ['Code128', 'Code39', 'EAN13', 'UPCA', 'QRCode'], frameTime: 1000, }, }; var myFrame = document.createElement("iframe"); var bStatic = (xAlign == 'none') && (yAlign == 'none') var myJSON = JSON.stringify(scannerSettings); var srcURL = 'https://websdk.datasymbol.com/srvhost/srv?ss=' + encodeURIComponent(myJSON) + '&tid=' + sWebSDKKey; var myFrame = document.createElement("iframe"); myFrame.setAttribute('id', 'DataSymbolFrame'); myFrame.setAttribute('src', srcURL); myFrame.setAttribute('allow', 'camera'); myFrame.setAttribute('style', 'opacity:' + opacity + ';position:' + (bStatic?'static':'fixed') + ';z-index:10001;left:' + leftPos + 'px;top:' + topPos + 'px;overflow:hidden; display:block; margin:0; padding:0; width:' + viewWidth + 'px; height:' + viewHeight + 'px;' + addFrameStyle); myFrame.setAttribute('scrolling', 'no'); myFrame.setAttribute('frameborder', '0'); var currScript = document.getElementById("DataSymbolScript"); currScript.parentNode.insertBefore(myFrame, currScript.nextSibling); window.addEventListener("resize", function(e) { setWinPos(); } ); document.body.onload = function(e) { setWinPos(); }; function setWinPos() { if( xAlign != 'none' ) { if( xAlign == 'left' ) leftPos = alignGap; if( xAlign == 'right' ) leftPos = document.documentElement.clientWidth - viewWidth - alignGap; } if( yAlign != 'none' ) { if( yAlign == 'top' ) topPos = alignGap; if( yAlign == 'bottom' ) topPos = document.documentElement.clientHeight - viewHeight - alignGap; } myFrame.style.left = leftPos + 'px'; myFrame.style.top = topPos + 'px'; } </script>
After embedding this code, Barcode Scanner should start working.
How do you know if a barcode has been decoded?
Use this code.
This code doesn't do anything useful with the barcode, it just throws a notification with the barcode text "alert(sBarcode);"<script> function bin2String (decodingResult, dataEncoding) { return String.fromCharCode.apply(null, decodingResult.data); } window.onmessage = function (e){ if (!e || !e.data.msgType || e.data.msgType != 'DataSymbolBarcode') return; var decodingResult = e.data.decodingResult; for (var i = 0; i < decodingResult.length; ++i) { var sBarcode = bin2String(decodingResult[i]); alert(sBarcode); } } </script>
A minimal knowledge of JavaScript will allow you to use the decoded barcode to a greater advantage.
As you may have noticed "Hosted Barcode Scanner" contains some settings. You can change them.
<script id='DataSymbolScript'> const viewWidth = 320; const viewHeight = 240; var leftPos = 0; var topPos = 0; const xAlign = 'none'; //none, left, right, float const yAlign = 'none'; //none, top, bottom, float const alignGap = 10; const opacity = 1.0; const addFrameStyle = ''; //additional style settings, for example: 'border: solid 2px #fff;' const sWebSDKKey = ''; var scannerSettings = { camera: { resx: 640, resy: 480, }, barcode: { barcodeTypes: ['Code128', 'Code39', 'EAN13', 'UPCA', 'UPCA'], frameTime: 1000, }, };









<!DOCTYPE html> <html> <head></head> <body> Hello, this is main html <br><br> <!-- Barcode Scanner Embedding --> <script id='DataSymbolScript'> const viewWidth = 320; const viewHeight = 240; var leftPos = 0; var topPos = 0; const xAlign = 'none'; //none, left, right, float const yAlign = 'none'; //none, top, bottom, float const alignGap = 10; const opacity = 1.0; const addFrameStyle = ''; //additional style settings, for example: 'border: solid 2px #fff;' const sWebSDKKey = ''; var scannerSettings = { camera: { resx: 640, resy: 480, }, barcode: { barcodeTypes: ['Code128', 'Code39', 'EAN13', 'UPCA'], frameTime: 1000, }, }; var myFrame = document.createElement("iframe"); var bStatic = (xAlign == 'none') && (yAlign == 'none') var myJSON = JSON.stringify(scannerSettings); var srcURL = 'https://websdk.datasymbol.com/srvhost/srv?ss=' + encodeURIComponent(myJSON) + '&tid=' + sWebSDKKey; var myFrame = document.createElement("iframe"); myFrame.setAttribute('id', 'DataSymbolFrame'); myFrame.setAttribute('src', srcURL); myFrame.setAttribute('allow', 'camera'); myFrame.setAttribute('style', 'opacity:' + opacity + ';position:' + (bStatic?'static':'fixed') + ';z-index:10001;left:' + leftPos + 'px;top:' + topPos + 'px;overflow:hidden; display:block; margin:0; padding:0; width:' + viewWidth + 'px; height:' + viewHeight + 'px;' + addFrameStyle); myFrame.setAttribute('scrolling', 'no'); myFrame.setAttribute('frameborder', '0'); var currScript = document.getElementById("DataSymbolScript"); currScript.parentNode.insertBefore(myFrame, currScript.nextSibling); window.addEventListener("resize", function(e) { setWinPos(); } ); document.body.onload = function(e) { setWinPos(); }; function setWinPos() { if( xAlign != 'none' ) { if( xAlign == 'left' ) leftPos = alignGap; if( xAlign == 'right' ) leftPos = document.documentElement.clientWidth - viewWidth - alignGap; } if( yAlign != 'none' ) { if( yAlign == 'top' ) topPos = alignGap; if( yAlign == 'bottom' ) topPos = document.documentElement.clientHeight - viewHeight - alignGap; } myFrame.style.left = leftPos + 'px'; myFrame.style.top = topPos + 'px'; } </script> Barcode: <h3 id='barcodeTxt'></h3> <!-- Catch Barcode Event --> <script> function bin2String (decodingResult, dataEncoding) { return String.fromCharCode.apply(null, decodingResult.data); } window.onmessage = function (e){ if (!e || !e.data.msgType || e.data.msgType != 'DataSymbolBarcode') return; var decodingResult = e.data.decodingResult; for (var i = 0; i < decodingResult.length; ++i) { if(decodingResult[i].type == 'LinearUnrecognized' || decodingResult[i].type == 'QRCodeUnrecognized' || decodingResult[i].type == 'DataMatrixUnrecognized' || decodingResult[i].type == 'PDF417Unrecognized' || decodingResult[i].type == 'AztecUnrecognized' || !decodingResult[i].barcodeAtPoint ) continue; var sBarcode = bin2String(decodingResult[i]); document.getElementById('barcodeTxt').innerText = sBarcode; } } </script> </body> </html>
OnLine Test