问题描述
我从这个网站上获取了qr代码阅读器代码https://github.com/wildabeast/BarcodeDemo\"。我正在jquerymobile中开发。我的问题是,如果我将扫描作为第一页,它完美地工作。如果我使用此页面而不是启动页面然后我面临问题,那就是当我第一次扫描图像时,它没有显示任何结果。如果第二次扫描得到结果,接下来第3次我没有得到结果,接下来第4次我得到结果,最后我得到的结果是偶数次扫描,这是我的应用问题。
I took the qr code reader code from this website "https://github.com/wildabeast/BarcodeDemo".I am developing in jquerymobile. My problem is if i place the scan as first page,it works perfectly. if i use this page other than startup page then i'm facing problem, that is when i scan the image first time ,it does not show any result. If scan 2nd time i got result, next 3rd time i am not getting result, next 4th time i am getting result, finally i got the result in even number of times scanning only, this is my application problem.
<span class="ui-btn-inner custom_button_red" style="margin-removed10px;"><span class="ui-btn-text" style="color:white;" id="scan">Scan & Buy</span></span>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="barcodescanner.js"></script>
<script type="text/javascript" src="childbrowser.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
here "app.initialize()" method is initiated from index.js
here i'm rendering the code in index.js :
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// `load`, `deviceready`, `offline`, and `online`.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById('scan').addEventListener('click', this.scan, false);
//document.getElementById('encode').addEventListener('click', this.encode, false);
console.log("hi");
},
// deviceready Event Handler
//
// The scope of `this` is the event. In order to call the `receivedEvent`
// function, we must explicity call `app.receivedEvent(...);`
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
scan: function() {
console.log('scanning');
//alert("1st click");
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
// scanner = cordova.require("cordova/plugin/BarcodeScanner");
//alert("lybrary loading");
scanner.scan( function (result) {
alert("scan function starts from here");
var regx = /^[A-Z0-9a-z]+$/;
if (regx.test(result.text))
{
/* alert("We got a QRcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n"); */
window.open("productinfonew.html?id="+result.text);
// document.getElementById("scan").innerHTML = result.text;
}
else
{
alert("Scanned Cancel,there is no html page with this name");
}
}, function (error) {
alert("scan function error");
console.log("Scanning failed: ", error);
} );
},
/* encode: function() {
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) {
alert("encode success: " + success);
}, function(fail) {
alert("encoding failed: " + fail);
}
);
} */
};
推荐答案
这篇关于为什么我在Jquerymobile中遇到Qr代码阅读器应用程序的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!