本文介绍了我无法使用javascript打开whatsapp api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我可以毫不费力地从标准href链接打开whatsapp。另外firefox工作得非常好。 但是我需要javascript来发送位置。所以我写了一个javascript代码。 如果我在私人网页上打开它并使用window.open命令它完美无缺。 但是如果我从普通标签打开它不起作用。我的网页也有ssl证书。 有什么问题? 我的尝试: $('#divKonumum')。click(function(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ var whatsAppLink ='whatsapp:// send?text = http://www.google.com/maps/place/'+position.coords.latitude+', '+ position.coords.longitude +'& phone = + 31623239665'; window.open(whatsAppLink); }); } }); 解决方案 ('#divKonumum')。click(function(){ if(navigator.geolocation){ navigator。 geolocation.getCurrentPosition(function(position){ var whatsAppLink ='whatsapp:// send?text = http://www.google.com/maps/place/'+position.coords.latitude+','+ position.coords.longitude +'& phone = + 31623239665'; window.open(whatsAppLink); }); } }); 我有一个技巧。 首先,我添加了一个带有id的标签。 后来我在页面加载时用jquery更改了它的href属性。 HTML Side < a id =aLocationhref =...> ... < / a> JS Side ('document').ready(function(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ var whatsAppLink ='whatsapp:// send?text = http://www.google.com/maps/place/'+position.coords.latitude+' , '+ position.coords.longitude +' &安培;电话= + 31623239665' ; I can open whatsapp from standart href link without any problem. Also firefox is works very good.But i need javascript for sending location. So i write a javascript code.If i open it on private web page and using window.open command it works perfectly.But if i open it from normal tab it doesn't work. My web page also has ssl certificate.What is the wrong ?What I have tried:$('#divKonumum').click(function(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var whatsAppLink='whatsapp://send?text=http://www.google.com/maps/place/'+position.coords.latitude+','+position.coords.longitude+'&phone=+31623239665'; window.open(whatsAppLink);});}}); 解决方案 ('#divKonumum').click(function(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var whatsAppLink='whatsapp://send?text=http://www.google.com/maps/place/'+position.coords.latitude+','+position.coords.longitude+'&phone=+31623239665'; window.open(whatsAppLink);});}});I hava a trick for it.Firstly i added an tag with id for it.Later i changed it's href attribute with jquery when page loading.HTML Side<a id="aLocation" href="..."> ...</a>JS Side('document').ready(function(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var whatsAppLink='whatsapp://send?text=http://www.google.com/maps/place/'+position.coords.latitude+','+position.coords.longitude+'&phone=+31623239665'; 这篇关于我无法使用javascript打开whatsapp api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 21:41