Monday 15 August 2011

javascript - a tag href data with newlines -



javascript - a tag href data with newlines -

i using angularjs , trying create scheme of downloading vcard created in javascript. in order vcard work on mobile, info needs downloaded through tag. problem everytime set href="data:text/vcard, "+ string saves vcard removes newlines. vcards work newlines

is there way maintain newline characters while saving data?

$scope.savevcard = function(){ var user = $scope.member; var out_string = 'begin:vcard\nversion:2.1\n\rn:' + user.last_name + ';' + user.first_name + ';;;\n\r'; //name out_string += 'fn:' + user.first_name + ' ' + user.last_name + '\n\r';//fn if (user.phone){ out_string += 'tel;cell:' + user.phone + '\n\r';} //phone if (user.email){ out_string += 'email;pref;internet:' + user.email + '\n\r';}//email if (user.prof_pic){ out_string += 'photo;png:'+user.prof_pic + '\n\r';}//picture out_string += 'end:vcard'; var = document.createelement('a'); a.href = 'data:text/vcard,' + out_string; a.target = '_blank'; a.download = 'contact.vcf'; console.log(a.href); document.body.appendchild(a); a.click(); document.body.removechild(a);

aha, figured out, utilize function encodeuricomponent().

var = document.createelement('a'); a.href = 'data:text/vcard,' + encodeuricomponent(out_string); a.target = '_blank'; a.download = 'contact.vcf'; console.log(a.href); document.body.appendchild(a); a.click(); document.body.removechild(a);

javascript download newline vcard

No comments:

Post a Comment