0
I need to make an anchor on my website and at the moment I have the following script:
<script>
$(document).ready(function() {
window.location.href='#foo';
});
</script>
It directs the page to the desired element, but when clicking on the page throughout it descends straight to where I want with the tag:
<a href="#" id="foo"></a>
On this page I have links to photo galleries. I click, I am redirected to the galleries normally and everything works as it should. But on the gallery page I have a button come back which, when clicking, should return to the previous page:
echo "<a href=\"about.php\" id=\"foo\" class=\"back\"><img src=\"images/left.png\"/> Voltar</a><br />";
It turns out that this way the anchor is not maintained. When I click back, the previous page is displayed, however, at the top of it, not at the anchor I was before entering the gallery.
How can I get the anchor to hold and when I click back, go back to the same position as the page I was on?
but I want it to leave the index2.php and go to index.php#foo, just by clicking the buttonback it activates the js and activates the #foo function, because the page does not go to the #foo function if not every time the user enters will go down to the gallery directly
– Tiago Teixeira
So. My solution does not solve your problem?
– Woss
if the function only goes back to the previous page with the msm link it came from, it will not work, but thanks for commenting on this function, I did not know.
– Tiago Teixeira
Explain your problem better then. The user is on
index.php#foo
, click to enter the gallery and go toindex2.php
. In theindex2.php
there must be the back button that goes toindex.php#foo
. Isn’t that?– Woss
I have the gallery at index.php, but the gallery is at the bottom of the page, when it clicks on the gallery, redirects to index2.php only with the photos of this gallery, and I have a href called back, which goes back to the index.php page, and I need that when it clicks back, it returns with #foo function
– Tiago Teixeira
Okay. My answer does just that. Why wouldn’t it work?
– Woss
according to you it goes back to the page the user came from, it will come from the index.php page, to index2.php, and when I click back, it will go back to index.php, because I didn’t put the #foo function on the whole index.php page, or I
– Tiago Teixeira
It goes back to the previous page, regardless of what it is, but I think I get your point. In case, the user will be in
index.php
(without#foo
), He goes into the gallery, and when he comes back, he has to go back toindex.php#foo
, correct?– Woss
Yeah, I guess I just got caught up in explaining, that’s exactly it.
– Tiago Teixeira
echo "<a href="candy.php#foo" class="back"><img src="images/left.png"/> Back</a><br />"; I’ve put this code now, it comes back with the foo function, but in my site, when I click on the tab to access the page, it redirects directly to the gallery, regardless of where I came from, I only need to get this problem, when clicking to access the page, it descend to the gallery, ( activate only the foo when back ad own gallery)
– Tiago Teixeira
How are you displaying the gallery link? Is it with PHP too? If so, add the snippet of code in the question that will be easier to give an example.
– Woss
<?php require_once 'gallery3.php'; ? > , I call the gallery by this link inside a box in the main php
– Tiago Teixeira