• Hi there,

    I want to create a dynamic link so that when you click on a post you from the homepage, you can click a link back to where you came from after reading the full post.

    I could just create a link back to the homepage and hard code it in, but what if the limit to the amount of posts per page is 3, and the post you’re viewing more of is 6 posts in. You wouldn’t want to go all the way back to the homepage and browse all the posts to get back to where you were.

    Am I making sense? It’s hard to explain without sounding confusing.

    Thanks in advance,

    Jodie

Viewing 8 replies - 1 through 8 (of 8 total)
  • <a href="javascript:javascript:history.go(-1)">Click here to go back to previous page</a>

    Thread Starter jo6891

    (@jo6891)

    Thank you!

    I will give that a go!

    As an alternative for cases when Javcascript is not available you could also use…

    <a href="<?php print $_SERVER['HTTP_REFERER'];?>">Go back</a>

    Thread Starter jo6891

    (@jo6891)

    Thanks for your reply.

    Which would you say is the ‘safest’ one to use in terms of accessibility?

    I’m not sure how reliable either are, but they will both do the same thing…

    Why don’t you test them and see how they work out…

    My suggestion would only work when a page has referred the browser to the page it’s on. Where as the JS solution should go-back to the previous page in the browser’s history… So the PHP approach will just create an empty link if the page is reached via typing it in the address bar, which won’t be a problem if the page is only typically reached by clicking links on your site….

    Neither way is 100% reliable, as is the case with most code…

    Which would you say is the ‘safest’ one to use in terms of accessibility?

    Neither?

    If you’re going to use javascript for a back link (which is perfectly acceptable from an accessibility point of view as you’re simply replicating the functionality of the browser Back button), then use javascript to generate the link. That way, no js, no link, no foul.

    @t31os: OK – so your version doesn’t use js but it will generate an empty link in some situations. Put a link on a page (even an empty link) and people will try to use it. At best, it will confuse some and undermine the confidence of others. At worst, the empty link can cause confusion for screen reader users (who use Link Lists for primary navigation) and create an unwanted hurdle for those who are forced to navigate pages by keyboard or using switch access.

    I’ve not tried this as, for the most part I’m not a big believer in replicating basic browser functionality but how about:

    <?php $back =$_SERVER['HTTP_REFERER'];
    if((isset($back) && $back !='') echo '<a href="'.$back.'">Go back</a>';?>

    Again, no recent browser history, no link.

    If you’re feeling clever, you could also add in an additional check to see if the referrer was on your domain/site. If the check fails – no link. Which would stop you sending someone back to another site…

    Esmi, totally agree, the initial example was done with simplicity in mind, hence i avoided the value check, as you’ve shown above.

    I’ve never actually used such a link, the idea just popped into my head when reading this thread.

    Ideally you would check if a value exists before creating the link… ??

    Thread Starter jo6891

    (@jo6891)

    Wow! This is quite complex for me now!

    Thankyou all for your advice. I will have a go and see which works best for me,

    Thanks again!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add a back link to a post’ is closed to new replies.