JW.
JW.

Reputation: 51638

Test whether document.domain was explicitly set

Is it possible to tell, using JavaScript, whether the document.domain property was explicitly set? Some browsers, like Firefox, distinguish between the case where it wasn't set, and the case where you call:

document.domain = document.domain;

But is there a way to programmatically tell the difference?

Upvotes: 2

Views: 575

Answers (1)

Jacksonkr
Jacksonkr

Reputation: 32207

as far as I know- you can not do what you're wanting to do natively. You may be able to save document.domain to a variable at the start of your page, then check against that value to see if that has changed:

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
}

Just an idea.

Upvotes: 1

Related Questions