-2

I have a client whose asked me to develop a page for his internal intranet / knowledgebase.

So we have

Page 1: which has links to a second page (or multiple second pages)

When the user clicks on the link on page 1 a new window opens (page 2). Page 2 actually loads page 1 again and page 1 is refreshed and loads the knowledge base article - effectively a pop-under. Where the knowledge base article is loaded underneath the new page which has the contents of the original page (plus a modal to say the knowledgebase article is in a separate tab).

So far, I have a working solution BUT the guy wants me to make it work so that the new window's (page 2) back button works. At the moment page 2 is a new tab so has no history (but the users see it as the original page).

So the question is - is there any way to give the new tab some history so that when they click on the back button, it takes them to where they expected.

Hope this makes sense to someone

bertster
  • 383
  • 1
  • 3
  • 17
  • 2
    Is there any benefit to this strange/complicated way of opening the resources? For it seems your problem really only exists because of it. – Yoshi Oct 27 '14 at 15:37
  • It's how the client wants it to work, not my spec but it's how he's asked for it – bertster Oct 28 '14 at 08:51
  • Well, to be honest, sometimes it's your responsibility as a developer to educate your client about why some request are just not reasonable. (imo) – Yoshi Oct 28 '14 at 09:12
  • I didn't come on here for lecture, I came on here for a technical query to be resolved. I have resolved it myself now. You have been no help - I wonder how many of your other posts are this unhelpful (imo) – bertster Oct 28 '14 at 13:19
  • I did not try to lecture you, I just stated my honest opinion (resulting from years of experience in the business). It's your choice to follow it or not. Nonetheless your reaction is quite harsh and I'm a bit baffled by it. SO is a platform of open discourse, if you can't handle peoples opions I'm sure you'll have a pretty hard time around here. – Yoshi Oct 28 '14 at 13:48

1 Answers1

0

I have found a solution to this:

First of all when opening the new window I pass a variable in the string i.e ?prevpage=http:/www.site.com/page.html

Next up on the new page I add:

<script>
window.history.pushState( {} , '', '<?php echo $prevpage;?>' );
</script>

Which puts the previous page in the new windows history (back button).

Then I put this at the bottom of the page which uses popstate to go back to the original pages URL when the back button is clicked:

<script>
window.addEventListener("popstate", function(e) {
window.location = "<?php echo $prevpage;?>";
});
</script>
bertster
  • 383
  • 1
  • 3
  • 17