[Javascript] window location hash

Glenn E. Lanier, II glenn_lanier at netzero.net
Fri Mar 23 15:06:51 CDT 2007


 


  _____  

From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
On Behalf Of Guillaume
Sent: Friday, March 23, 2007 6:39 AM
To: [JavaScript List]
Subject: Re: [Javascript] window location hash


Thanks all for your responses.
I've tryed the different suggestions. All work but don't solve the initial
bug.
I need the hash because I need bottom and top of page to be reached with a
keypress.
Here's an example: http://www.hablablow.com/devX/hash/hash.html
You'll see the bug when opening the url in Safari and in a tab.
Two keypress are active *b* ( reach bottom of page ) and *u* ( reach top of
page ).
Press any of these two and you'll see that Safari loops loading the page (
notice the loading icon in the tab above ).
Here's what I end with:

 var hashValue = "bottomPage";
 if (hashValue == window.location.hash)
{
window.location.hash = new String((new Date().getMilliseconds()));
}
window.location.hash = hashValue;
}

Here's a reminder of the bug description that occurs only on Safari:

(...)
- What is going on here?
Setting location.hash to the same value twice in a row causes Safari to
reload the page. Tested in Safari 1.1-1.2 and equivalent OmniWeb versions.
- What can be done to workaround this bug?
Don't set location.href to the same value twice in a row. If needed, set it
to an intermediate value in between.
(...)

Here's an example: http://www.hablablow.com/devX/hash/hash.html

Thanks.

Guillaume.




On 3/22/07, Glenn E. Lanier, II  <mailto:glenn_lanier at netzero.net>
<glenn_lanier at netzero.net> wrote: 



Untested, but would 

var hashValue = "bottomPage"; 
if (hashValue != window.location.hash) 
{ 
        window.location.hash = hashValue; 
} 



It will avoid the bug but probably will not do what is intended by the 
hash change in the first place. A slight modification: 

if (hashValue == window.location.hash) 
{ 
       window.location.hash = new String((new Date().getMilliseconds())); 
} 
window.location.hash = hashValue; 





[G>] Guillaume,
 
I don't have Safari to test on, but would the following work (and meet your
restriction of not setting the hash to the same value twice):
 

var hashValue = "bottomPage";
var hashValue1 = "bottomPageA";

window.location.hash = hashValue1;    // an Anchor item one line above/below
hashValue
window.location.hash = hashValue; 
 
It seems like this would always set your anchor to the proper place
(bottomPage), even if user has scrolled away from it (a la Nick's example),
and would never allow hash to be set to same value twice.
 
--G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070323/590dbf63/attachment.htm>


More information about the Javascript mailing list