Monday 1 May 2023

How to save vCards-js automatically on Iphone & Android contacts

i am trying to save a vcard on users phone (IOS & ANDROID). I am 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();
});

And it works, but this code on android phone first download a vcard and later users need to make a click on download to make import. What i want is when user go to this page , my contact save automatically on android without downloading any File. (On IOS is not a problem couse when user go to this web they redirect automatically to import contact)

NOTE: I have sow before an example with qr code. When i scan qr code they redirect me to import contact and what i need to do is only to click save on my phone

I want same thing as this https://www.qr-code-generator.com when click on vCard tab. But when page reload, not to scan qr code



from How to save vCards-js automatically on Iphone & Android contacts

No comments:

Post a Comment