Kiss (part 2)
Posted: 09/11/2008 Filed under: Uncategorized 1 Comment »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 code.google.com. I got what I want by using jquery. So this is my current solution. On the html page we at a little javascript: Volgens de check van jouw browser staat mijn PC nu WEL online.
'}";
// Load jQuery
google.load("jquery", "1");
// on page load complete, fire off a jQuery json-p query
// against Google web search
google.setOnLoadCallback(function() {
$.getJSON("http://java3.tisnix.be:8888/jason.php?callback=?",
function (data) {
document.getElementById("txtResult").innerHTML = data.responseData;
document.getElementById("txtResult").style.backgroundColor = "green";
});
});
jason.php just returns a little json structure:
<?php
// 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:'
$str .= ")";
echo $str;
?>
On our page we have a div with id txtResult which get replaced by the responseData when the page is loaded.
[...] a working solution can be found in kiss part 2 Possibly related posts: (automatically generated)XML database exampleSimple AJAX implementation for [...]