0

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?

1
  • Have you tried alerting location.href? Does is give you the expected result? Commented Nov 9, 2009 at 14:03

3 Answers 3

0

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)+')');
Sign up to request clarification or add additional context in comments.

6 Comments

That's right, but i simplified the script (cut the uri= stuff and so on). However, with a fixed URI it works!
Have you included the proper uri=... version inside @allowed_uris?
Also, what's the real URL you're trying to use? Fetching the current page (location.href) through an ACD proxy makes no sense whatsoever.
It makes sense in my case. I want to provide a special service to webmasters. therefore i need the cross domain stuff. to simplify the script inclusion for webmasters i have to use location.href and block not allowed uris from within ACD.
Erm. But the current page is already quite readable from JavaScript, there is no need to send a request to your server proxying to their server to return a page that's already loaded in the browser.
|
0

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);

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.