0
votes

After assigning this: window.onload = initfunction;

I want to append the AJAX cross domain script to the header:

function initfunction() {
 var dh = document.getElementsByTagName('head')[0];
 var script = null;
 script = document.createElement('script');
 script.setAttribute('src', 'http://whatever.com/cgi-bin/ACD/ACD.js?'+location.href);
 script.setAttribute('type', 'text/javascript');
 dh.appendChild(script);
  }

The script seems to be appended with the correct domain name, but Firebug says: "Failed to load source". If I type a fixed URL within the src attribute it works! e.g.:

script.setAttribute('src', 'http://whatever.com/cgi-bin/ACD/ACD.js?http://google.com');

Any ideas?

3
Have you tried alerting location.href? Does is give you the expected result?karim79

3 Answers

0
votes

Assuming we're talking about ajax-cross-domain.com's script, shouldn't it be:

script.setAttribute('src', 'http://whatever.com/cgi-bin/ACD/ACD.js?uri=('+encodeURIComponent(location.href)+')');
0
votes

Here is a simplified code snippet for test purposes. Just put this as an onload function or a script tag in the header. the webpage will continuously load...

var dh = document.getElementsByTagName('head')[0];
if(!dh)
{
  //html page without "head"
  head = document.createElement('head');
  document.appendChild(head);
}
var script = null;
script = document.createElement('script');
script.setAttribute('src', 'http://domain.com/cgi-bin/ACD/ACD.js?' + location.href);
script.setAttribute('type', 'text/javascript');
dh.appendChild(script);
0
votes

OK i got the solution. The problem was not the "location.href" itself, but a rule in our firewall that prohibits a GET request to the own server. Therefore the script throwed a timeout.