What are tags?
detection change of location.hash
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > Javascript web-programming > detection change of location.hash 19 August 2009 14:05:53

  Top users: 
  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

detection change of location.hash

User 18 August 2005 21:13:42
 Hi,
A page I have shows a different background colour depending on the
hash portion of the url as it is first loaded. For example a link to
mysite/mypage#0000F­F would result in a page with a blue background. But
another link, this one to mysite/mypage#FF000­0, would not give me a red
background if directed to the window where mypage#0000FF was loaded
just one moment ago. This is normally to be expected, because the browser
thinks same page, no load event, basta.
If I use the search portion, for obvious reasons, that is treated a new page
load, even when it is from the cache, but I need the hash here. So how do I
detect in mypage the moment when the hash string is changed by a user click
event on another page in another window, perhaps even from another domain?

Hope this is clear, thanks for any ideas,
Thomas







Add comment
Lee 18 August 2005 21:52:27 permanent link ]
 User said:>
Hi,>A page I have shows a different background colour depending on the>hash portion of the url as it is first loaded. For example a link to>mysite/mypage#00­00FF would result in a page with a blue background. But>another link, this one to mysite/mypage#FF000­0, would not give me a red>background if directed to the window where mypage#0000FF was loaded>just one moment ago. This is normally to be expected, because the browser>thinks same page, no load event, basta.>If I use the search portion, for obvious reasons, that is treated a new page>load, even when it is from the cache, but I need the hash here. So how do I>detect in mypage the moment when the hash string is changed by a user click>event on another page in another window, perhaps even from another domain?>
Hope this is clear, thanks for any ideas,

So, if I understand correctly, you'd like a small pet that sits in
a cage and sings, but it has to be a horse. Is that about right?

Add comment
Web.Dev 18 August 2005 23:34:00 permanent link ]
 Hi User,

User wrote:
[snip]> You can set up event listeners around every> link on the page to catch the event of such in-page moves, but now suppose> our user blurs the browser window, returns to this posting and clicks on> this link http://www.jibberin­g.com/faq/#FAQ4_41 instead. The browser pops> back up, he ends up at the same spot, but the event has not been captured> because it occured in his newsreader client where he follows the newsgroup!
[snip]>
Thanks again,> Thom

One solution that I'm thinking of off the top of my head is what you
already described.

1. Set up event listeners in the page for which the background color
will change. (No need to set up listeners on other pages, because once
they open up this page, the window.location.has­h will kick in)
2. Try something like below for the blurring and focusing of the
window.

<script type = "text/javascript">
function bgChange()
{
document.bgColor = window.location.has­h;
}

window.onload = bgChange;
window.onfocus = bgChange;
</script>

Hope this helps. :)­

Add comment
Kevin Newman 18 August 2005 23:38:43 permanent link ]
 User wrote:> Hi,> A page I have shows a different background colour depending on the> hash portion of the url as it is first loaded. For example a link to> mysite/mypage#0000F­F would result in a page with a blue background. But> another link, this one to mysite/mypage#FF000­0, would not give me a red> background if directed to the window where mypage#0000FF was loaded> just one moment ago. This is normally to be expected, because the browser> thinks same page, no load event, basta.> If I use the search portion, for obvious reasons, that is treated a new page> load, even when it is from the cache, but I need the hash here. So how do I> detect in mypage the moment when the hash string is changed by a user click> event on another page in another window, perhaps even from another domain?


The only way I've found is to use setInterval with a function that
checks it current status. I'd love to find a way to do this in a more
event driven way though, so if you find something please share :-)­

http://www.unfocus.­com/Projects/History­Keeper/

BTW, just to point out a browser bug that you might run into - if the
user manually updates the hash in IE or Mozilla, scripts will no longer
be able to update that portion of the url.

Kevin N.
Add comment
Kevin Newman 18 August 2005 23:45:08 permanent link ]
 web.dev wrote:> One solution that I'm thinking of off the top of my head is what you> already described.>
1. Set up event listeners in the page for which the background color> will change. (No need to set up listeners on other pages, because once> they open up this page, the window.location.has­h will kick in)> 2. Try something like below for the blurring and focusing of the> window.>
<script type = "text/javascript">>­ function bgChange()> {> document.bgColor = window.location.has­h;> }>
window.onload = bgChange;> window.onfocus = bgChange;> </script>>
Hope this helps. :)­>

This is an interesting idea - are there events fired when the user
presses the forward and back buttons?

Kevin N.
Add comment
Kevin Newman 19 August 2005 20:36:29 permanent link ]
 User wrote:> Hi,> A page I have shows a different background colour depending on the> hash portion of the url as it is first loaded. For example a link to> mysite/mypage#0000F­F would result in a page with a blue background. But> another link, this one to mysite/mypage#FF000­0, would not give me a red> background if directed to the window where mypage#0000FF was loaded> just one moment ago. This is normally to be expected, because the browser> thinks same page, no load event, basta.> If I use the search portion, for obvious reasons, that is treated a new page> load, even when it is from the cache, but I need the hash here. So how do I> detect in mypage the moment when the hash string is changed by a user click> event on another page in another window, perhaps even from another domain?>
Hope this is clear, thanks for any ideas,> Thomas>

In css there is a :target pseudo element that can be used to cause the
style of the anchor that is targeted by the hash to change when that
hash is active.

So I guess the question is, is there a way to detect when the target
changes?

Or is it possible to detect when the style of the anchor element(s)
changes (or when the applied pseudo element changes)?

This would only work in Mozilla and other browsers that support the
:target pseudo element, but it's a start.

Kevin N.

http://www.unfocus.­com/Projects/IE7/com­patibility/target.ht­ml#oranges

Note: IE7 seems to just trap mouseup events on everything, so this would
not work for your (or my) purposes (pressing the back button does not
update the target in IE with Dean's IE7).
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > Javascript web-programming > detection change of location.hash 19 August 2009 14:05:53

see also:
updating a file in place is almost…
How can I free allocated memory?
creating module
pass tests:
KaKaya ti HEKA? -)
see also:
mts top7
i'm new here
Inizio.

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .