Why isn't location.replace() overrideable?

J

James Marshall

I'm trying to override location.replace() but I can't. I can override
window.open(), document.write(), and other built-in methods, but not
location.replace(). Here's a demo that overrides two built-in methods,
then reports on them:

location.replace= function (url) { alert(url) } ;
alert('location.replace=\n'+location.replace) ;
document.write= function (html) { alert(html) } ;
alert('document.write=\n'+document.write) ;

The first alert shows location.replace is still "[native code]", while the
second alert shows that document.write has been correctly overridden.

The same happens if the first two lines above are put into the "onclick"
attribute of a button, so it wouldn't seem to be that the window.location
object's not created yet, etc.

Any ideas? Also, while window.open() seems overrideable in most browsers,
am I wrong to assume that location.replace() should be also?
(document.write is overrideable in Mozilla, which I'm using.) Note that
I'm using the actual window etc. objects this time, not the Window etc.
prototypes.

Thanks a lot!


James
.............................................................................
James Marshall (e-mail address removed) Berkeley, CA @}-'-,--
"Teach people what you know."
.............................................................................
 
V

Vicomte De Valmont

in IE it actually replaces both, yet on NS6 it overrides only, as yuou
report in your example, document.write and still says native code for
location.replace. I think you were referring to NS6 ++.

It cannot be overridden also by using the constructor new Function, which I
tried.

I don't know the explanation, I'd need to know the internal arrangements of
the interpreter. Yet, it is possible that a few objects are sort of
"protected" by their signatures.
This might be a case in point affecting NS6, whereas a case for IE could
be:

"I can't see any other viable explanation for behaviours like those that
when looping navigator.plugins trigger an Error:
alert(typeof navigator.plugins);
for(var i in navigator.plugins){alert(i)}
The loop yields an error (in Explorer 6 at least), although the typeof
returns Object and therefore the object should have been liable to be looped
by a for-in cycle like absolutely all objects are "

That is, it seems that there are a few dependances of the objects which
aren't accessible. Sorry that i don't have a better answer, maybe other
users have it: i can just stress for you that a few objects deny themselves
to tasks that other objects, apparently exactly on the same tier of the
hierarchy, lend themselves to without problems. That is, it might be, say,
not your "fault"!

ciao
Alberto
http://www.unitedscripters.com/




James Marshall said:
I'm trying to override location.replace() but I can't. I can override
window.open(), document.write(), and other built-in methods, but not
location.replace(). Here's a demo that overrides two built-in methods,
then reports on them:

location.replace= function (url) { alert(url) } ;
alert('location.replace=\n'+location.replace) ;
document.write= function (html) { alert(html) } ;
alert('document.write=\n'+document.write) ;

The first alert shows location.replace is still "[native code]", while the
second alert shows that document.write has been correctly overridden.

The same happens if the first two lines above are put into the "onclick"
attribute of a button, so it wouldn't seem to be that the window.location
object's not created yet, etc.

Any ideas? Also, while window.open() seems overrideable in most browsers,
am I wrong to assume that location.replace() should be also?
(document.write is overrideable in Mozilla, which I'm using.) Note that
I'm using the actual window etc. objects this time, not the Window etc.
prototypes.

Thanks a lot!


James
.............................................................................
James Marshall (e-mail address removed) Berkeley, CA @}-'-,--
"Teach people what you know."
.............................................................................
 
T

Thomas 'PointedEars' Lahn

James said:
I'm trying to override location.replace() but I can't.

I guess it is protected because it manipulates the history. Besides,
(window.)location is a host object, do not expect it to be supported.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top