简体   繁体   English

jquery 显示不适用于 href 电话点击 android chrome

[英]jquery show not working with href tel click on android chrome

I created a webpage for mobile devices that I want to open a jquery ui dialog and then do the click of the number when link is clicked.我为移动设备创建了一个网页,我想打开一个 jquery ui 对话框,然后在单击链接时单击数字。 all I did was a我所做的只是一个

$( "#dialog" ).dialog( "open" ) 

and then a然后一个

$("#link").click().  

The link is href="tel:2342342345" .链接是href="tel:2342342345"

If I am not on mobile, it will open the dialog fine, but obviously, ignores the click because it is not a phone.如果我不在手机上,它会很好地打开对话框,但很明显,它会忽略点击,因为它不是手机。 I have been trying different things for an hour and here are some of the results:我已经尝试了一个小时不同的事情,以下是一些结果:

If I do a settimeout on the click, if it is less than about a second, it will not open the dialog and bring up the phone.如果我在点击时设置超时,如果它不到大约一秒钟,它不会打开对话框并调出电话。 If it is over a second, it will open the dialog and then just ignore the phone.如果超过一秒钟,它将打开对话框,然后忽略电话。 I tried add an on focus event to the window thinking once the phone call is done and they go back to the chrome, it would open the dialog, but it does not.我尝试在窗口中添加一个焦点事件,认为一旦电话完成并且他们返回到 chrome,它会打开对话框,但它不会。 I tried adding an ajax call before the click to open the window later, but that seems to work like the settimeout does.我尝试在单击之前添加一个 ajax 调用以稍后打开窗口,但这似乎与 settimeout 一样。 If it is quick, it just opens the phone interface and never pops up the dialog and if it is slow, it never opens the phone interface.如果速度快,它只是打开电话界面,从不弹出对话框,如果速度慢,它永远不会打开电话界面。

I also tried it by just creating a div with display:none and then doing a $('#div').show() and it acts exactly the same.我还尝试通过创建一个带有 display:none 的 div 然后执行$('#div').show()并且它的行为完全相同。

Not sure if it will work on other phone types as I have not tested.不确定它是否适用于其他手机类型,因为我没有测试过。

I also tried adding an onblur event to do this, but that is not triggered either on android while working on desktop.我还尝试添加一个 onblur 事件来执行此操作,但是在桌面上工作时也不会在 android 上触发。

 <html> <head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content=""> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <style></style> </head> <body> <div> <a href="#" id="link">call</a> <!--open browser devtool and check in mobile divase --> </div> <script> $(document).ready(function(){ if(window.innerWidth < 769){ $('#link').attr("href", 'tel:2342342345'); } if(window.innerWidth > 769){ $('#link').attr("href", '#'); } console.log($('#link').attr("href")) }) </script> </body> </html>

unable to understand what you want .无法理解你想要什么。 I think you want this according to your writing "If I am not on mobile, it will open the dialog fine, but obviously, ignores the click because it is not a phone. I have been trying different things for an hour and here are some of the results:"我认为你想要根据你的写作“如果我不在手机上,它会很好地打开对话框,但显然,忽略点击,因为它不是手机。我已经尝试了一个小时的不同的东西,这里有一些结果:”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM