Kiss (part 2)

I previously tried to create an easy solution to detect if my computer was up and running but I got stuck with some interdomain related stuff. On my second try i was playing with iframes.

I added a hidden Iframe to the page which i tested using this code:

function testFrame() {
if (document.getElementById("check").contentDocument.getElementById("txtOnline") == null) {
if (cnt++ < 5) setTimeout(testFrame(),5000);
} else {
content = document.getElementById("check").contentDocument.getElementById("txtOnline").textContent;
document.getElementById("txtResult").textContent = content;
document.getElementById("txtResult").style.backgroundColor = "green";

It didn’t worked. Again I got troubles with interdomain stuff.

I found the real solution at I got what I want by using jquery. So this is my current solution. On the html page we at a little javascript:

// Load jQuery
google.load("jquery", "1");
// on page load complete, fire off a jQuery json-p query
// against Google web search
google.setOnLoadCallback(function() {
function (data) {
document.getElementById("txtResult").innerHTML = data.responseData;
document.getElementById("txtResult").style.backgroundColor = "green";

jason.php just returns a little json structure:

// Not sure of deze nodig is
header ("Content-Type: application/json; charset=utf-8");
// een heel eenvoudige response
$str = "";
$str .= $_GET['callback'];
$str .= "(";
$str .= "{responseData:'

Volgens de check van jouw browser staat mijn PC nu WEL online.

$str .= ")";
echo $str;

On our page we have a div with id txtResult which get replaced by the responseData when the page is loaded.

One Comment on “Kiss (part 2)”

  1. […] a working solution can be found in kiss part 2 Possibly related posts: (automatically generated)XML database exampleSimple AJAX implementation for […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s