2011-08-26 80 views
2

是否可以使用JavaScript判斷document.domain屬性是否已明確設置?測試是否明確設置了document.domain

document.domain = document.domain; 

但是,有沒有以編程方式有什麼區別:一些瀏覽器,如Firefox,它沒有設置的情況下,和之間,您撥打的情況下區分?

+0

請參閱http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do –

回答

1

據我所知,你不能做自己想做的事。如果已經改變了你可能能夠document.domain的保存到一個變量在你的頁面的開始,然後覈對該值看:

var dd = document.domain; 

function isDDnatural() { 
    if(dd == document.domain) return true; 
    return false; 
} 

window.onload = function() { 
    // pretending a lot is going on here 
    console.log(isDDnatural()); // this will return false if the document.domain had changed 
} 

只是一個想法。

+0

但是如果您調用了'document.domain = document.domain',那仍然會返回真正。 –

+0

我只是在說一個主意。我希望別人能夠加入進來。這太糟糕了,不適合你。祝你好運。 – Jacksonkr

相關問題