开发者

Cross Domain Javascript with External Source

If a.com loaded b.com/b.js as an external source. What is the domain within j.js? a.com, b.com or 开发者_如何学JAVAboth?


JavaScript runs on the client side. If it looks at window.location it will see the current site - if that wasn't the case, all our JS from CDN's would point to the CDN's :)


example.com can load any resource from any domain, but the code still has the same origin policy so it can only talk to example.com. You do not get special rights by loading it from the other domain.

Imagine if linking to a file would all of the sudden allow cross domain talking. If that was the case, any site could link to a JS file of a bank, email provider, etc and be able to make Ajax calls behind the scenes. Not good!

One great reason for loading content from another domain is cookies are not sent, meaning smaller payload. Also if you are loading from a CDN, people may already have the files in their browser's cache so no download time!

If you are looking to make cross domain calls, you either need to look at JSONP, CORS, or proxies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜