Skip to content Skip to sidebar Skip to footer

Is It Possible To Overwrite Window.location Function With A Custom Function?

Is it possible to disable, or even better, replace with a custom function, window.location? This question is related: Disable a built-in function in javascript (alert) While it wor

Solution 1:

try this

var _window = {
       location: "myLocation"
};

(function (window) {
   console.log(window.location);
}(_window));

Solution 2:

I don't believe you can reassign window.location. From MDN:

Summary

Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.

https://developer.mozilla.org/en/DOM/window.location

As it takes a value like a property, how would you "reassign" the object/function to another value? I don't think it's possible due to the property behavior.


Post a Comment for "Is It Possible To Overwrite Window.location Function With A Custom Function?"