Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript document.domain and port number

Tags:

javascript

dns

Prerequisites:

The browser keeps the domain as a pair ('domain','port') and setting document.domain to its own value (or any other correct one) causes the setter to overwrite port number with null (ok, WTF!?)

See: What does document.domain = document.domain do?

Question:

Is it possible to invoke the setter in a way that preserves the port or allows one to set it?

like image 297
naugtur Avatar asked Nov 03 '11 09:11

naugtur


People also ask

What is document domain?

The domain property of the Document interface gets/sets the domain portion of the origin of the current document, as used by the same-origin policy.

Does domain include port?

No. The document. domain includes only the host name.

How can we get hostname and port information in Javascript?

If you only want to return the hostname value (excluding the port number), use the window. location. hostname method instead. This will return a string value containing the hostname and, if the port value is non-empty, a : symbol along with the port number of the URL.

What is domain in Javascript?

Definition and Usage. The domain property returns the domain name of the server (the document was loaded from). The domain property returns null if the document was created in memory.


1 Answers

No.

If you never set the document.domain it's "special" it knows its never been set, and also includes the port.

Once you set it it's just a simple string, no port, and will only match other frames that have that same string.

A never set document.domain will NOT match a document.domain that was set - even if both look like they are exactly the same thing. It has nothing to do with the port. A changed document.domain will never match one that was not changed, even if it was changed to "itself".

like image 79
Ariel Avatar answered Oct 22 '22 19:10

Ariel