location.hash does not work without setTimeout

D

danep

Basically, my problem is exactly as described in the subject. The
problem is somewhat intermittent and unpredictable, but the majority
of the time if I just have a statement such as

window.onload=location.hash('somewhere');

the URL is indeed appended, i.e. www.example.com/index.php#somewhere,
but window itself doesn't actually move to the bookmark. However, if
I do something like

window.onload=setTimeout("location.hash('somewhere')",0)

it works fine. On very large pages, the timeout actually has to be a
second or two. Any idea why this is happening? I don't know much
about JS, but my thought is that it's trying to move to that bookmark
before it has actually been loaded in the page; the timeout forces it
to wait for the rest of the page to load before going to the bookmark.

Any thoughts?
 
D

danep

danep said the following on 7/22/2007 9:41 PM:





location.hash is not a function, it is a property of the location Object.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Oh boy, now I feel silly. Thanks for smacking me on the head. :)
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top