473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Why isn't location.replace() overrideable?

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 ja***@jmarshall.com Berkeley, CA @}-'-,--
"Teach people what you know."
.................................................. ...........................
Jul 20 '05 #1
2 3598
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" <js*@jmarshall.com> ha scritto nel messaggio
news:Pi**************************************@jmar shall.com...
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 ja***@jmarshall.com Berkeley, CA @}-'-,--
"Teach people what you know."
.................................................. ...........................

Jul 20 '05 #2
James Marshall wrote:
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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andoni | last post by:
Hi, I am only writing for IE 5.5+ so no need for compatibility at all ;-) I am trying to get my users to logoff which they finish on a particular page. This is no problem (or should be no...
5
by: spam_me_ not | last post by:
I already understand that one cannot disable a browser's forward and back functions. This is a situation where I have code working in Mozilla V1.6 and would like something similar for Opera and...
10
by: Roland | last post by:
Hello, the example code is the following(the number in parentheses at the beginning are just for reference)(The complete HTML file is at the end of this article): (1)window.location =...
1
by: solutions | last post by:
Hi, Here is my relevant code for an arbitrary page (let's call it PAGE_B): <body onload="window.location.hash='anchor';"> With this code, if the user goes from PAGE_A to PAGE_B, he will jump...
2
by: JHB | last post by:
Hi, How can I do a location.replace when I use a form, like when I use a href? This works. <a href="Ny HTML-side20.htm"; method="post" id="frm" name="BrugerHovedSide"...
3
by: Al | last post by:
Hi all... I have created an aspx page that contains an animated GIF. I am using javascript and location.replace to redirect from this page to another aspx page which takes several seconds to...
9
by: Jean Pierre Daviau | last post by:
Hi everybody, I have this function in a page (namely cours.html) function go(inValue) { var lien = 'file:///F:/MyWebs/jeanpierredaviaucom/httpdocs/cours1.html?T1=' + document.R.T1.value;
4
by: /dev/null | last post by:
I tried soemthing like: if (top != self) top.location.href = self; or if (window == top) top.location.replace("index.html"); doesn't work.
12
by: Jack | last post by:
Since, I have not got some desired advise, I am reposting this for some asnwer/valuable suggestion. Thanks. THE FOLLOWING IS A PART OF CODE FROM A ASP PAGE <% sql01 = "SELECT COUNT(*) AS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.