Tirato via quindi ci potrebbe essere
qc
tanto per darti un'idea:
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Box per le news by Whisher</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript" type="text/javascript">
var page = "file.php";//File delle news formato news uno | news due | etc
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
var receiveReq=false; //Clear our fetching variable
try {
receiveReq = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
receiveReq = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (e) {
receiveReq = false;
}
}
if (!receiveReq && typeof XMLHttpRequest!='undefined') {
receiveReq = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
return receiveReq;
}
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();
//Initiate the asyncronous request.
function getNews(getValue) {
//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
//Setup the connection as a GET call to your page
//True explicity sets the request to asyncronous (default).
var url = page+"?add=" + getValue;
receiveReq.open('GET', url , true);
//Set the function that will be called when the XmlHttpRequest objects state changes.
receiveReq.onreadystatechange = handlegetNews;
//Make the actual request.
receiveReq.send(null);
}
}
//Called every time our XmlHttpRequest objects state changes.
function handlegetNews() {
//Check to see if the XmlHttpRequests state is finished.
if (receiveReq.readyState == 4) {
//Set the contents of our span element to the result of the asyncronous call.
var text = receiveReq.responseText;
alert( text);
}
}
function testScript()
{
addEvent(document.getElementsByTagName('body')[0], 'click', prova, false);
}
function prova(e)
{
var addClick = 0;
target = getTarget(e);
if(target.tagName.toLowerCase()=='img')
{
//Qui devi trovare qc per gestire l'attributo src
//perchè cambia di volta in volta questo è un'esempio
if(target.getAttribute('src').indexOf('trade'))
{
addClick = 1;
}
}
getNews(addClick);
}
function addEvent(elm, evType, fn, useCapture)
{
if (elm.addEventListener)
{
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
};
function getTarget(e)
{
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target){return false;}
return target;
};
addEvent(window,'load',testScript, false);
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"></s'+'cript>');
</script>
</body>
</html>
e il semplice file.php per vedere se tutto funzia
Codice PHP:
<?php
echo $_GET['add'];
?>