Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override window.location.hostname in Javascript?

Tags:

javascript

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)
like image 662
Rob Avatar asked May 09 '13 12:05

Rob


People also ask

Can window location origin be changed?

The only property you can't set is window. location. origin . This property is read-only.

What does Window location do in Javascript?

The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.

What is window location origin in Javascript?

origin. The origin read-only property of the Location interface is a string containing the Unicode serialization of the origin of the represented URL.


1 Answers

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.

like image 144
Mark Schultheiss Avatar answered Nov 14 '22 11:11

Mark Schultheiss