How To Put Click to Call On Your Website-Step 1
Upto this i assume you have sound knowledge of a linux system and have an Asterisk PBX running.If not, lets first check how this WIFI technology work from here
Create a new directory, under your main www directory, called "clickcall". Create a new file in there, called "clickcalltest.html". Copy the following code into that file. You will need to change "example.com" to your own domain.
Code:
// VoIP User Click To Call System 1.0 BETA // AJAX Main Functions // From http://www.voipuser.org/forum_topic_9696.html // May 2007 //
// Set up our XMLHttpRequest Object var XMLHttpRequestObject = false; var currentStatus = 'offline'; var newStatus = 'offline';
if (window.XMLHttpRequest) { // Mozilla, Safari... XMLHttpRequestObject = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Internet Explorer try { XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
if (!XMLHttpRequestObject) { // Remove this once you're done debugging and let failures go. Worst case, the visitor just won't see the button // Some users disable Java in their browsers. Not a great deal we can do about that. alert('Failed to create XMLHTTP instance.'); }
// This function checks the presence flag on the webserver and outputs the button, or not function getData(dataSource, divID) { if (XMLHttpRequestObject) { var obj = document.getElementById(divID); XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function () { if ( (XMLHttpRequestObject.readyState == 4) && (XMLHttpRequestObject.status == 200) ) { if (XMLHttpRequestObject.responseText == 1) { newStatus = 'online'; } if (XMLHttpRequestObject.responseText == 0) { newStatus = 'offline'; } if (currentStatus != newStatus) { if (newStatus == "online") { obj.innerHTML = ' '; } else { obj.innerHTML = ''; } currentStatus = newStatus; }
} } }
XMLHttpRequestObject.send(null); }
var timerID = null
function StartTimer() { getData('http://www.example.com/clickcall/getstatus.php', 'targetDiv'); timerID = self.setTimeout("StartTimer()", 500); }
