开发者

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.

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.

Update

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"); also opens a new window then opens the call dialog box, which isn't a great user experience on iphone 3gs/4.


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(); });

in the iframe code (if it has jQuery), and a function in your main script called iframe_loaded which does the window.location call.

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>

...so the onload calls iframe_loaded() which does 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);

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!


Have you tried window.open(url); where the url is "tel:18001234567" ?
Seems like that should work, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜