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#0000FF would result in a page with a blue background. But another link, this one to mysite/mypage#FF0000, 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?
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#0000FF would result in a page with a blue background. But>another link, this one to mysite/mypage#FF0000, 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?
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.jibbering.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.hash 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.hash; }
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#0000FF would result in a page with a blue background. But> another link, this one to mysite/mypage#FF0000, 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
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.
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.hash 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.hash;> }>
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#0000FF would result in a page with a blue background. But> another link, this one to mysite/mypage#FF0000, 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.
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).
If you would like to report an abuse of our service, such as a spam message, please . Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .