PDA

View Full Version : self.location and Netscape


cfcoder
06-25-2002, 06:25 PM
I'm having problems using a named anchor in the following code:


<script language="Javascript">
<!--
window.self.location='#message';
//-->
</script>


This works fine in IE but dosen't in NS. In NS the page stops loading at the point it reaches the JS code. :(

There's a simple answer, I bet, but I'm not on top of JS so your solution would be a grate help.

:thumbsup:

eak
06-25-2002, 06:31 PM
you should try putting that in an onload statement. i think the problem is that the anchor doesnt exist yet when the browser reaches that code so it has no where to send you to. if you call that code when the page is loaded it should work because all the elements have been loaded.


<script language="Javascript">
<!--
window.onload=function(){window.self.location='#message';}
//-->
</script>

jkd
06-25-2002, 09:53 PM
BTW, window.self is redundant:

self == window //true

Which means you are saying window.window, and:

window.window == window //true

So a:

self.location.href
or a
window.location.href
is all that is needed, or you could even just go:
location.href

As window is the top-level object anyway.