I have a couple of ad networks that have been able to integrate a passback URL (requested when a paid ad impression is not available) but one ad network can only accept a passback script tag, which I don't have.
The passback script needs to load the contents of a URL (a 728x90 image or flash banner) into itself (it also needs to execute the Javascript that it loads). Can anyone help me construct a passback script tag?
I tried this:
<SCRIPT language="Javascript">
// loads within itself, in the 728x90 banner space
document.write("<SCR"+"IPT language=\'Javascript\' src=\'http://www.mydomain.com/passback.php\'></SCR"+"IPT>");
</SCRIPT>
But got script errors. Any ideas?
Just an idea. What does it give if you try this ?
<SCRIPT language="JavaScript" type="text/javascript">
var script = document.createElement("script");
script.type = "text/javascript"; // This is for HTML 4.01 validation
script.src = "http://www.mydomain.com/passback.php";
document.getElementsByTagName("head")[0].appendChild(script);
</SCRIPT>
The script already provided is close to the one I always use for this:
var js = document.createElement("script");
js.type = "text/javascript";
js.src = "//www.mydomain.com/passback.php";
document.getElementsByTagName('head')[0].appendChild(js);
The only thing that is different is that the URL scheme is not specified therefore if you are running on an http server then the http url will be called and if you run on https then https will be called - mixing them would be reason that you scripts may not load.
With your script error I would suggest using Chrome and the developer tools - this would allow you to see exactly which line is giving you that error.
The following function loads another document into document body. The URL of the new document should be in the same domain which is http://www.mydomain.com/ in your case.
You need to save the following script as a .js file and put it where the ad should be placed.
function load(url) {
var req = null;
if (window.XMLHttpRequest) {
req = new window.XMLHttpRequest();
}
else if (window.ActiveXObject) { //fallback
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
if (req) {
req.open("GET", url, false);
req.send(null);
return req.responseText;
}
}
document.write(load("http://www.mydomain.com/passback.php"));