4

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.

marissajmc
  • 2,583
  • 1
  • 22
  • 19

2 Answers2

5

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!

JoLoCo
  • 1,355
  • 2
  • 13
  • 23
1

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

Mike Hay
  • 2,828
  • 21
  • 26
  • No, window.open("tel:num"); is not reliable enough when called with tracking code on the same button. window.open("tel:num"); also causes a window to open and then the call dialog box to open, which isn't a great user experience. – marissajmc Aug 30 '11 at 02:36
  • Ah, ok. So, I assume that window.location = "tel:18001234567"; doesn't work for you either. It might help if you posted the javascript that is executed with your onclick, so that people here had more info about what you're doing and why it's unreliable. – Mike Hay Aug 30 '11 at 18:56
  • Actually window.location = "tel:18001234567" was the solution, I just needed to make sure I called it only after my tracking iframe had loaded. – marissajmc Aug 31 '11 at 02:46