我已经尝试了好一阵子了。我修改了JavaScript代码以创建VCard。当按下提交按钮时,脚本当前会生成QR码。如果我用手机扫描代码,它将打开我的联系人,并填写所有内容。我想做的是绕过QR码过程,并在按下“提交”按钮时使脚本自动打开。是否有一种简单的方法来获取此代码并简单地将其导出并打开,而不是保存并生成QR码?
这是按钮代码。
<input type="button" name="submit" value="Generate">
这是JavaScript
<script type="text/javascript">
var vcard= {
str_start:'BEGIN:VCARD\nVERSION:3.0\n',
str_vcard:'BEGIN:VCARD\nVERSION:3.0\n',
str_end:'\nEND:VCARD',
goog_chart:'http://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=',
form:[],
get_field: function(field){
for(var i in vcard.form){
if(vcard.form[i].name === field){
return vcard.form[i].value.replace(/^\s+|\s+$/g,"");
}
}
},
add_you: function(){
var first_name = "MARC",
last_name = "MATTEO",
birthday = vcard.get_field('birthday'),
gender = vcard.get_field('gender');
vcard.str_vcard += 'N:'+last_name+';'+first_name+'\n'+
'FN:'+first_name+' '+last_name;
if(birthday !== ''){ vcard.str_vcard += '\nBDAY:'+birthday; }
if(gender !== ''){ vcard.str_vcard += '\nX-GENDER:'+gender; }
},
add_address: function(){
var
org_street = "org_street",
org_city = "org_city",
org_region = "org_region",
org_post = "org_post",
org_country = "org_country";
if(org_street+org_city+org_region+org_post+org_country !== ''){
vcard.str_vcard += '\nADR;TYPE=work:;;'+org_street+';'+org_city+';'+org_region+
';'+org_post+';'+org_country;
}
},
add_tel: function(){
var
work = "8005551212";
if(work !== ''){ vcard.str_vcard += '\nTEL;TYPE=work:'+work; }
},
add_email: function(){
var work = "testemail@email.com";
if(work !== ''){ vcard.str_vcard += '\nEMAIL;TYPE=internet,work:'+work; }
},
add_url: function(){
var
work = "http://www.mywebsite.com";
if(work !== ''){ vcard.str_vcard += '\nURL;TYPE=work:'+work; }
},
add_work: function(){
var name = "My Business Name",
title = "CEO";
if(name !== ''){ vcard.str_vcard += '\nORG:'+name; }
if(title !== ''){ vcard.str_vcard +='\nTITLE:'+title; }
},
add_note: function(){
var name = "My custom note can be anything";
if(name !== ''){ vcard.str_vcard += '\nNOTE:'+name; }
},
add_social: function(){
var facebook = "https://www.facebook.com/myaccount",
twitter = "https://www.twitter.com/testaccount",
instagram = "https://www.instagram.com/marcanthonyphoto",
linkedin = "https://www.linkedin.com/marcanthonyphoto";
if(facebook !== 'https://www.facebook.com/'){ vcard.str_vcard += '\nX-SOCIALPROFILE;type=facebook:'+facebook; }
if(twitter !== 'https://www.twitter.com/'){ vcard.str_vcard +='\nX-SOCIALPROFILE;type=twitter:'+twitter; }
if(instagram !== 'https://www.instagram.com/'){ vcard.str_vcard +='\nX-SOCIALPROFILE;type=Instagram:'+ instagram; }
if(linkedin !== 'https://www.linkedin.com/'){vcard.str_vcard +='\nX-SOCIALPROFILE;type=linkedin:'+ 'https://www.linkedin.com/marcanthonyphoto';}
},
save: function(){
vcard.form = $('form').serializeArray();
vcard.add_you();
vcard.add_address();
vcard.add_tel();
vcard.add_email();
vcard.add_url();
vcard.add_work();
vcard.add_note();
vcard.add_social();
vcard.str_vcard += vcard.str_end;
$('textarea[name="vcard"]').val(vcard.str_vcard);
$('#qr').attr('src',vcard.goog_chart+vcard.str_vcard.replace(/\n/g,'%0A'));
vcard.str_vcard = vcard.str_start;
}
};
//input click function
$(function(){
$('input[name="submit"]').click(vcard.save);
});
</script>