1.window.domain
強制設定相關頁面 window.domain相同
a.html
document.domain = 'a.com';
b.html
document.domain = 'a.com';
2.window.name 同一視窗,動態改變鏈結 window.name 是不變的,最多保留2m資料
a.html
window.name="aaaaa";
window.location.href="b.html";
b.html
alert(window.name); //aaaaa
3.xhr
「xhr2」 全稱 「xmlhttprequest level2」 是html5提供的方法,對跨域訪問提供了很好的支援,並且還有一些新的功能。
* ie10以下的版本都不支援
* 只需要在伺服器端頭部加上下面兩句**:
header( "access-control-allow-origin:*" );
header( "access-control-allow-methods:post,get" );
4.jsonp
a.html
$.ajax(
,error : function() });
function jsoncallback(data);
b.html
window.addeventlistener('message', function(event)
}, false
);
6.web sockets
js跨域 ajax跨域 跨域方式(前端)
跨域方式 cors 跨域資源共享 當使用xmlhttprequest傳送請求時,瀏覽器會自動加上乙個請求頭 origin,後端在接受到請求後確定響應後會在response headers中加入乙個屬性 access control allow origin,值就是發起請求的源位址 瀏覽器得到響應會進...
js中的跨域方法總結
什麼是跨域?瀏覽器的安全策略,只要協議,網域名稱,埠有任何乙個不同,就被當做不同的域。下面對的同源檢測 a.html 同源 b.html 同源 8080 不同源 不同源 不同源 1,jsonp方法 2,document.domain 原理 document.domain設定成相同的網域名稱,來訪問i...
js跨域問題
什麼是跨域?概念 只要協議 網域名稱 埠有任何乙個不同,都被當作是不同的域。1.document.domain 跨子域 這個是範圍最小的乙個。比如a.example.com 中寫了乙個iframe,其中src example.com 但是因為是不同域的就無法寫js獲取iframe中的document...