Передача результата отсканированного QR-кода не работает в рамках первоначально вызванной функции openQRCamera(node)
. Я добавил кнопку на обработанную страницу, чтобы вытащить это - Pull Variables. Тестовый код:
http://www.attendthemeeting.com/QR/testCode.png
Код:
https://codepen.io/samisosa-3/pen/wZYZJP
Я проверил все в консоли. Любой вклад приветствуется.
function openQRCamera(node) {
var reader = new FileReader();
reader.onload = function() {
node.value = "";
qrcode.callback = function(res) {
if(res instanceof Error) {
alert("No QR code found. Please make sure the QR code is within the camera's frame and try again.");
} else {
node.parentNode.previousElementSibling.value = res;
}
};
qrcode.decode(reader.result);
};
reader.readAsDataURL(node.files[0]);
document.getElementById("showMe").style.display="block";
myLog();
}
function myLog(){
Vcard0 = document.getElementById("iCard").value;
//test vcard scan variable set
console.log(Vcard0);
//remove beginning and end vcard
Vcard0 = Vcard0.replace('BEGIN:VCARDVERSION:2.1',"");
Vcard0 = Vcard0.replace('END:VCARD',"");
//insert colons for splitting pairs
Vcard0 = Vcard0.replace('FN:',':Fn:');
Vcard0 = Vcard0.replace('N:',':N:');
Vcard0 = Vcard0.replace('ORG:',':ORG:');
Vcard0 = Vcard0.replace('TITLE:',':TITLE:');
Vcard0 = Vcard0.replace('TEL;WORK;VOICE:',':TEL:');
Vcard0 = Vcard0.replace('EMAIL;WORK;INTERNET:',':EMAIL:');
//add colons to prepare qrcode for split function
var Vcard1 = Vcard0.replace(/(\r\n|\n|\r)/gm,":");
Vcard1 = Vcard1.replace('::',':');
var qrArray = Vcard1.split(":");
var qrArrayJSON = JSON.stringify(qrArray);
//test array pairs
for(i=0;i<qrArray.length;i++)
{
console.log(qrArray[i]);
}
console.log(qrArrayJSON);
//search for titles and set variable to next element (value is the next field)
Fn = qrArray[(qrArray.indexOf("Fn"))+1];
N = qrArray[(qrArray.indexOf("N"))+1];
ORG = qrArray[(qrArray.indexOf("ORG"))+1];
TITLE = qrArray[(qrArray.indexOf("TITLE"))+1];
TEL = qrArray[(qrArray.indexOf("TEL"))+1];
EMAIL = qrArray[(qrArray.indexOf("EMAIL"))+1];
//check for null
if (Fn === null || Fn === " ")
{Fn = "";}
if (N === null || N === " ")
{N = "";}
if (ORG === null || ORG === " ")
{ORG = "";}
if (TITLE === null || TITLE === " ")
{TITLE = "";}
if (TEL === null || TEL === " ")
{TEL = "";}
if (EMAIL === null || EMAIL === " ")
{EMAIL = "";}
//test variables
console.log(Fn);
console.log(N);
console.log(ORG);
console.log(TITLE);
console.log(TEL);
console.log(EMAIL);
//set text inputs to variables
document.getElementById("hideMe").style.display = "none";
document.getElementById("iFN").value=Fn;
document.getElementById("iORG").value=ORG;
document.getElementById("iTITLE").value=TITLE;
document.getElementById("iTEL").value=TEL;
document.getElementById("iEMAIL").value=EMAIL;
document.getElementById("iNOTES").value=NOTES;
}