I'm curious is there any possibility to override window.location.hostname? I didn't found anything about that on google... probably I searched for wrong phrases because I think that someone had to asked it before me.
Sorry for my bad english.
EDIT: To be more specific. I don't want to do that. I want to know if someone can override that to execute my code.
In general - I have list of domains that I approve to execute some code. When
if (window.location.hostname === myurl.com)
gives true then they are good to go, other case they will have alert or something. I don't want someone to do something like that:
window.location.hostname = "myurl.com"
if (window.location.hostname === myurl.com)
The only property you can't set is window. location. origin . This property is read-only.
The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
origin. The origin read-only property of the Location interface is a string containing the Unicode serialization of the origin of the represented URL.
According to this reference: https://developer.mozilla.org/en-US/docs/DOM/window.location these are properties. Thus you can "set them to navigate to another URL" - however, that would result in a redirection.
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