Reputation: 7704
Ok so my question title may have been a little confusing.
Here's my example:
www.WebsiteA.com is hosting MyFile.js at http://www.WebsiteA.com/MyFile.js. This file makes an AJAX request for http://www.WebsiteA.com/location/file
When this Javascript file is included on WebsiteB through the script tag, will the Javascript run into cross-domain issues or is it based upon where the actual Javascript file is hosted?
Hopefully you understand me ok, thanks for any responses :)
Mike
Upvotes: 0
Views: 184
Reputation: 42099
It depends on if you're using a relative path or a full path.
Upvotes: 0
Reputation: 20049
You can do this - this is how most javascript based analytics trackers work (Google Analytics etc)
Upvotes: 0
Reputation: 344291
The same origin policy applies to the domain of the site (ie. the URL you see in your browser's address bar). The JavaScript file can be hosted on any domain. The <script>
tag is exempt from the same origin policy.
If the address bar in the browser is showing www.websiteB.com
, you will bump into the same origin policy if you make a request to a file on www.websiteA.com
. This is irrelevant of where the .js file is hosted. If this is the case, you may want to check out the following Stack Overflow post for a few workarounds:
Upvotes: 2