I'm trying to save a vCard on the user's phone (IOS and ANDROID). I'm using this code
window.addEventListener("load", function () { // Contact Information var contact = { ... }; // create a vcard file var vcard = "BEGIN:VCARD\nVERSION:3.0\n" + "N:" + contact.name + ";;;\n" + "FN:" + contact.name + "\n" + "TEL;CELL:" + contact.phone + "\n" + "TEL;CELL:" + contact.mobile + "\n" + "EMAIL;HOME:" + contact.email + "\n" + "ADR;HOME:" + contact.address + "\n" + "ORG;WORK:" + contact.organization + "\n" + "TITLE:" + contact.title + "\n" + "URL:" + contact.url + "\n" + "NOTE:" + contact.notes + "\n" + "END:VCARD"; // var vcard = "BEGIN:VCARD\nVERSION:4.0\nFN:" + contact.name + "\nTEL;TYPE=work,voice:" + contact.phone + "\nEMAIL:" + contact.email + "\nEND:VCARD"; var blob = new Blob([vcard], { type: "text/vcard" }); var url = URL.createObjectURL(blob); const newLink = document.createElement('a'); newLink.download = contact.name + ".vcf"; newLink.textContent = contact.name; newLink.href = url; newLink.click(); // window.close(); });
It works, but this code on Android phones first downloads the vcard, then the user needs to click download to import. What I want is that when the user comes to this page, my contacts are automatically saved on Android without downloading any files. (On iOS this is not a problem as when users visit this site they are automatically redirected to import contacts)
Note:
I have broadcast an example with a QR code before. When I scan the QR code they redirect me to import contacts and all I need to do is click save
I want the same thing as https://www.qr-code-generator.com when the vCard tab is clicked. But when the page reloads, the QR code is not scanned
You need to add a web share API method. According to your code, you can add navigator.share(), with conditions such as if to check whether this API is supported by the browser. Other download links will be automatically downloaded.
Like the updated code below: -