简体   繁体   中英

window.location is an object?

window.location = null; // But it redirects to http://example.com/null

is it possible to delete window.location?

I am writing a proxy and I want to make sure the the script inside the request url won't redirect to their page.

window.location = 'http://actual-urlexample.com';

My idea is to replace the window.location with our object so that we can control the above code for my proxy sever. I want to know only one thing: whether window.location is an object or not. How an event(new url is loading) occurring when we assigning a value to window.location ?

There're at least two obvious ways to find out:

  • Your browser's JavaScript console:

     >>> typeof window.location "object" 
  • Your favourite documentation :

    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.

No offense but I'd like you see you overriding a builtin object if you even need to ask whether it's an object ;-P

Edit: A little clarification—I suppose that technically speaking location is actually a property of the window object that contains a Location object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM