跨域问题


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

同一域:指协议、域名,端口号都相同,否则为跨域。
表现为:如在a.com/index.html 利用iframe引用了b.com/index.html,
那么:在a.com/index.html无法更改b.com/index.html的对象,如dom,css等,但是可读取的。即只读
反之,在b.com/index.html中对a.com/index.html也是只读的。
//在b.com/index.html中可用document.referrer来引用a.com/index.html的网址
不过,可在a.com/index.html利用对b.com/index.html的访问权限,在b.com中创建一对象,此对象在a.com中是可以操作的。

对于主域相同而子域不同的例子,可以通过设置document.domain的办法来解决。
具体的做法是可以在http://www.a.com/a.html和http://script.a.com/b.html两个文件中分别加上document.domain = ‘a.com’;然后通过a.html文件中创建一个iframe,去控制iframe的contentDocument,这样两个js文件之间就可以“交互”了。当然这种办法只能解决主域相同而二级域名不同的情况

引用:http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html