Comments (5)
I don't use REACT, this is pure VANILLA JS.
You should adapt it to your needs, but it does exactly what you asked for your project.
from html5-qrcode.
I don't use REACT, this is pure VANILLA JS.
You should adapt it to your needs, but it does exactly what you asked for your project.
I did it. Thank you for your support
from html5-qrcode.
Please, follow this code @hoaipd
HTML
<div id="qr-reader"></div> <button id="startButton">Start Scan</button> <button id="stopButton" style="display:none;">Stop Scan</button>
JAVASCRIPT
`document.addEventListener('DOMContentLoaded', function() {
let lastResult;
let html5QrCode = new Html5Qrcode("qr-reader");
function onScanSuccess(decodedText, decodedResult) {
if (decodedText !== lastResult) {
lastResult = decodedText;
window.open('https://optwo.id/?scan=' + decodedText, '_blank');
}
}
function startScan() {
Html5Qrcode.getCameras().then(cameras => {
if (cameras && cameras.length) {
// Assumendo che l'ultima fotocamera nell'elenco sia quella posteriore
let cameraId = cameras[cameras.length - 1].id;
html5QrCode.start(
cameraId,
{ fps: 10, qrbox: { width: 300, height: 300 } },
onScanSuccess,
errorMessage => {
console.log(`QR Code no longer in front of camera.`);
})
.catch(err => {
console.log(`Unable to start scanning, error: ${err}`);
});
}
}).catch(err => {
console.error("Impossibile accedere alla lista delle telecamere", err);
});
}
function stopScan() {
html5QrCode.stop().then(ignore => {
console.log("Scanning stopped.");
}).catch(err => {
console.error("Unable to stop scanning.", err);
});
}
document.getElementById('startButton').addEventListener('click', function() {
startScan();
this.style.display = 'none';
document.getElementById('stopButton').style.display = 'block';
});
document.getElementById('stopButton').addEventListener('click', function() {
stopScan();
this.style.display = 'none';
document.getElementById('startButton').style.display = 'block';
});
});`
from html5-qrcode.
Please, follow this code @hoaipd
HTML
<div id="qr-reader"></div> <button id="startButton">Start Scan</button> <button id="stopButton" style="display:none;">Stop Scan</button>
JAVASCRIPT
`document.addEventListener('DOMContentLoaded', function() { let lastResult; let html5QrCode = new Html5Qrcode("qr-reader"); function onScanSuccess(decodedText, decodedResult) { if (decodedText !== lastResult) { lastResult = decodedText; window.open('https://optwo.id/?scan=' + decodedText, '_blank'); } } function startScan() { Html5Qrcode.getCameras().then(cameras => { if (cameras && cameras.length) { // Assumendo che l'ultima fotocamera nell'elenco sia quella posteriore let cameraId = cameras[cameras.length - 1].id; html5QrCode.start( cameraId, { fps: 10, qrbox: { width: 300, height: 300 } }, onScanSuccess, errorMessage => { console.log(`QR Code no longer in front of camera.`); }) .catch(err => { console.log(`Unable to start scanning, error: ${err}`); }); } }).catch(err => { console.error("Impossibile accedere alla lista delle telecamere", err); }); } function stopScan() { html5QrCode.stop().then(ignore => { console.log("Scanning stopped."); }).catch(err => { console.error("Unable to stop scanning.", err); }); } document.getElementById('startButton').addEventListener('click', function() { startScan(); this.style.display = 'none'; document.getElementById('stopButton').style.display = 'block'; }); document.getElementById('stopButton').addEventListener('click', function() { stopScan(); this.style.display = 'none'; document.getElementById('startButton').style.display = 'block'; });
});`
Does it resolve to the page that displays the website's camera access request, and after clicking accept button, does it display the camera? And I want it's only display camera, don't show button 'Start scan' and 'Stop scan', show camera when accept request access of website. I use ReactJs. Thank you!
from html5-qrcode.
const html5QrCode = new Html5Qrcode(
"reader", { formatsToSupport: [ Html5QrcodeSupportedFormats.QR_CODE ] });
const qrCodeSuccessCallback = (decodedText, decodedResult) => {
/* handle success */
};
const config = { fps: 10, qrbox: { width: 250, height: 250 } };
// If you want to prefer front camera
html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
if i want to prefer back camera, How do I change the config?
from html5-qrcode.
Related Issues (20)
- Compatibility Issue - [iOS 17.2.3] [Safari] - Only black screen is visible once camera permission is given. HOT 1
- Unable to scan PDF-417 barcode HOT 3
- Add ability to take a screenshot of barcode with the device's camera
- Barely functioning in iOS. Perfect in Android. QR recognition script or app? HOT 10
- Compatibility - iOS 17 - All browsers - Rear camera is not working HOT 1
- Turn off file upload HOT 5
- Compatibility - [OS] [Browser] - NotAllowedError: Permission denied HOT 9
- Problem with turning off barcode scanning when the browser is closed or the browser goes to the background on mobile
- Adjusting the Camera Resolution for Flutter Web App HOT 10
- Camera closed after each succesful scan. HOT 2
- [Feature Request] Angular 16 framework support for this library HOT 4
- Barcode scanner outputs the barcode value with junc characters in between
- Set the position of qrbox in top using camera with full screen
- Barcode 39 is scanned unreliably on Android HOT 1
- setTimout violation problem
- Not scanning white barcodes
- [Feature Request] Make it easier to override this package with local changes.
- QR-code image scanning feature get Bug !
- iphone error: undefined is not an object HOT 1
- Compatibility - [IOS] [Chrome , Safari] - Iphones aren't reading barcode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html5-qrcode.