[Javascript] window location hash

Guillaume javascript at webdesignofficina.com
Sat Mar 24 09:33:05 CDT 2007


Glenn,

Thanks for your reply... I'm not sure of what you mean... I've tryed the 
solution below by setting 2 different values for the same destination.
But the bug remains visible in Safari.
Here's a test page: http://www.hablablow.com/devX/hash/hashG.html

Any other ideas someone ( with Safari under hands )....

Thank you all for helping so far: Glenn, Nick, Matt and Flávio...

I really appreciate.

Regards.

Guillaume.


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.

>  
>
>     ------------------------------------------------------------------------
>     *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 <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
> ------------------------------------------------------------------------
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070324/b1e5b1fc/attachment.htm>


More information about the Javascript mailing list