简体   繁体   English

如何使用javascript(iphone)触发点击通话

[英]How to trigger click-to-call with javascript (iphone)

I have a link in a mobile webpage that needs to track an advertiser clickTag and then activate click-to-call. 我在移动网页中有一个链接,需要跟踪广告客户clickTag,然后激活点击通话。

I've got the tracking working but I don't know how to trigger the tel:1800123456; 我有跟踪工作,但我不知道如何触发tel:1800123456; with javascript. 用javascript。 Any ideas? 有任何想法吗? This is not a web app; 这不是一个网络应用程序; it's a standard html page. 这是一个标准的html页面。 I can use jQuery. 我可以使用jQuery。

Update 更新

Just calling window.open("tel:num"); 只需调用window.open("tel:num"); after adding a tracking iframe on click was not reliable enough because sometimes the call dialog box would open before the iframe had finished loading. 在点击上添加跟踪iframe后不够可靠,因为有时调用对话框会在iframe完成加载之前打开。

window.open("tel:num"); also opens a new window then opens the call dialog box, which isn't a great user experience on iphone 3gs/4. 还打开一个新窗口然后打开调用对话框,这对iphone 3gs / 4来说不是一个很好的用户体验。

Do you have any control over the tracking iframe? 你对跟踪iframe有什么控制权吗? If so, you could call a function which makes the window.location call once it's loaded. 如果是这样,你可以调用一个函数,该函数在加载后进行window.location调用。 Something like 就像是

$(document).ready(function() { window.iframe_loaded(); });

in the iframe code (if it has jQuery), and a function in your main script called iframe_loaded which does the window.location call. 在iframe代码中(如果它有jQuery),以及主脚本中一个名为iframe_loaded的函数,它执行window.location调用。

If you can't set the code within the iframe but can edit the iframe container code, then you could do this... 如果您无法在iframe中设置代码但可以编辑iframe容器代码,那么您可以执行此操作...

<iframe id="whatever" onload="iframe_loaded();" width="400" height="200"></iframe>

...so the onload calls iframe_loaded() which does window.location... ...所以onload调用iframe_loaded(),它执行window.location ...

If you don't have control over the iframe or its content, then easy kludge would be to just wrap the window.location call in a timeout, ie 如果你无法控制iframe或其内容,那么简单的kludge就是在超时中包装window.location调用,即

setTimeout('window.location="tel:18001234567";', 500);

The 500 at the end will delay it by half a second. 最后的500将延迟半秒。 (Increase it if your iframe is slow to load.) It's not as elegant, but might work fine and users probably won't notice a small delay! (如果你的iframe加载缓慢,请增加它。)它不是那么优雅,但可能工作正常,用户可能不会注意到一个小延迟!

Have you tried window.open(url); 你试过window.open(url); where the url is "tel:18001234567" ? 网址是“tel:18001234567”?
Seems like that should work, right? 看起来应该有用,对吗?

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

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