如何使用javascript(iphone)触发点击通话 [英] How to trigger click-to-call with javascript (iphone)
问题描述
我在移动网页中有一个链接,需要跟踪广告客户clickTag,然后激活点击通话。
I have a link in a mobile webpage that needs to track an advertiser clickTag and then activate click-to-call.
我有跟踪工作,但我不知道如何触发 tel:1800123456;
with JavaScript的。有任何想法吗?这不是一个网络应用程序;这是一个标准的html页面。我可以使用jQuery。
I've got the tracking working but I don't know how to trigger the tel:1800123456;
with javascript. Any ideas? This is not a web app; it's a standard html page. I can use jQuery.
更新
只需调用 window.open(tel:num);
在点击后添加跟踪iframe不够可靠,因为有时调用对话框会在iframe完成加载之前打开。
Just calling 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.
window.open(tel:num);
还打开一个新窗口然后打开调用对话框,这不是在iphone 3gs / 4上获得了极佳的用户体验。
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.
推荐答案
您是否可以控制跟踪iframe?如果是这样,你可以调用一个函数,该函数在加载后进行window.location调用。类似
Do you have any control over the tracking iframe? If so, you could call a function which makes the window.location call once it's loaded. Something like
$(document).ready(function() { window.iframe_loaded(); });
(如果它有jQuery),主脚本中的函数名为iframe_loaded window.location调用。
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中设置代码但可以编辑iframe容器代码,那么您可以这样做......
If you can't set the code within the iframe but can edit the iframe container code, then you could do this...
<iframe id="whatever" onload="iframe_loaded();" width="400" height="200"></iframe>
...所以onload调用iframe_loaded()做window.location ......
...so the onload calls iframe_loaded() which does window.location...
如果你无法控制iframe或其内容,那么简单的kludge就是在超时中包装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, i.e.
setTimeout('window.location="tel:18001234567";', 500);
最后500将延迟半秒。 (如果你的iframe加载缓慢,请增加它。)它不是那么优雅,但可能工作正常,用户可能不会注意到一个小延迟!
The 500 at the end will delay it by half a second. (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!
这篇关于如何使用javascript(iphone)触发点击通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!