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?
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.
No. The document. domain includes only the host name.
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.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With