Page 1 of 1

anchor fails on 1st visit, works on 2nd+

Posted: Mon Jul 18, 2005 5:28 pm
by devgirl
I'm new to php and have written a simple link as follows:

echo '<a href="'.$_SERVER['PHP_SELF'].'?album='.$dir.'&picture='.$nextImage.'#pin">Next</a>';

I have the anchor as <a name=pin></a> about halfway down the page.

When I follow the link the first time, the anchor is ignored. Every single call I make afterwards to the same link, the anchor works. This is obviously not much good for visitors to my site who may only view pictures once. The URL appears correctly in the browser with #pin on the end.

How on earth can I make it work on the first call? It's like the page needs to be cached before it will work. (viewing with IE6), has anyone else seen this and got round it?

Posted: Mon Jul 18, 2005 5:58 pm
by Chris Corbyn
Have you got a link to the page? I don't see a reason for that other than perhaps the time it may be taking for the anchor to actually load in the code (pardon the little rhyme :P)

Posted: Mon Jul 18, 2005 6:04 pm
by devgirl
Hmm. I hadn't thought about the timing aspect.

You can see the problem at http://www.fayewilliams.com/gallery-mai ... 250062.jpg

Select 'next' and it will load the page from the top instead of jumping to the anchor point. If you then select 'previous' it does work, and then 'next' after that and its ok. You can only ever see the problem once on each picture and then you have delete all your cache to recreate it.

Same on IE and Firefox. It's driving me mad!

Posted: Mon Jul 18, 2005 6:20 pm
by Chris Corbyn
Hmm... doesn't look like a timing issue... the only thing that loads slow (although nothing unordinary) is the image.

I can't get it to work even the once using FF 1.05 on Linux.

<off topic>
I kinda got sucked into looking throguh the photography ;) I love that stuff.. I used to photograph trees too. Silhouetted on colorful skies - we're going back about 7 years now when I was doing GCSE (16 yo) exams... my final piece was two complimentary A1 chalk pastel works based on the photography I'd done throughout the year and partly influenced by Atkinson Grimshaw (Oil on canvas artist who loved his moonlight scenes - though not always with trees :?).
</off topic>

Try this although it *shouldn't* make a difference:

Code: Select all

<!-- Not sure it's valid XHTML -->
<a name=&quote;pin&quote; />

and this

<!-- Added quote marks -->
<a name=&quote;pin&quote;></a>
EDIT | It's working now :? I think it is a caching issue. I know there's a fix... I just can't think of it :( - someone clever should pick up on that note and provide the fix ;)

Posted: Mon Jul 18, 2005 6:36 pm
by devgirl
Your final submission for Art sounds cool :-). I wish I had more time for working on things like that.

I tried your suggestions but no luck - it sort of 'feels' like it's something to do with the anchor being on the same page that's being reloaded, so I might restructure things a bit later on this evening.

If I find a solution I'll post it...

Posted: Mon Jul 18, 2005 6:40 pm
by Chris Corbyn
I was about to say I've preloaded images with JavaScript but I hate relying on JS to do trivial things.

So...

http://www.netmechanic.com/news/vol6/css_no18.htm

CSS can preload the image in the previous page...

Not 100% how well it will work but it could be worth a shot ;)

Posted: Mon Jul 18, 2005 6:46 pm
by s.dot
I don't really see the problem either. However, whenever someone clicks a next link, you could call a function onLoad() to go to that element

Something along the lines of

Code: Select all

<html>
<body onLoad=&quote;document.location.getElementById(&quote;pin&quote;);&quote;>
My javascript is barely existant, so that may not be the proper code.

d11wtq | It's not - but nice pseudo code ;)

Posted: Mon Jul 18, 2005 7:09 pm
by devgirl
Ah ha! Your comments about pre-loading the images made me think about things in a different way, and I suddenly realised what was happening...

My style sheet doesn't specify the space the image will use, so it was going to the anchor on load up, but the page was too short to show it because the image hadn't arrived to fill the space. On subsequent visits, the image is cached, hence the page is physically longer and the anchor works.

I've modified the style to create an area that the picture will go in when it loads. It now works every time :-D.

Thanks guys, sometimes you just need a prod in the right direction.

Posted: Mon Jul 18, 2005 7:18 pm
by s.dot
scrotaye wrote: d11wtq | It's not - but nice pseudo code ;)
muaha, the idea was there! the code just needed to follow.