0

I am making a web page that has multiple different pages under multiple directories.

The way this is currently set up is that there is a main page A.

On Page A there is a menu that has links to other pages. These pages are loaded into a div on page A using AJAX.

I'm currently trying to make it so users could bookmark the page with the current content from the menu they selected already loaded. I've done this by making a GET variable and posting the page "directory/name". The issue now though is to make it so the user can press the back button on their browser giving the same functionality of a page that isn't loaded like this.

Is there some way that back functionality can be used to get the previous pages and load them? I know the easiest way of doing this is forgetting about the loading of the pages and it will fix pretty well all of the problems, however at this point I'm curious of a workaround for this.

Javascript is being used but the jQuery library is not.

Cheers.

EDIT: Adding basic code functionality.

<div id="content">
<p>Hello</p>
</div>

<p onclick="load('dir/file')">Link1</p>
<p onclick="load('dir/file')">Link2</p>

<script>
window.onbeforeunload = function() {
 load(getVar("page"));
}
function getVar (name) {
     name = RegExp ('[?&]' + name.replace (/([[\]])/, '\\$1') + '=([^&#]*)');
     return (window.location.href.match (name) || ['', ''])[1];
}
function load(val) {
    loadPage(val+".html", "content");  //This just does an ajax call and puts the content into the second value.
    window.history.pushState({},"IBM","https://labweb.torolab.ibm.com/groups/websphere/WASL3/l3_new/index.php?page="+val);
}
</script>

I think that's the basic functionality of it.

Jake Alsemgeest
  • 626
  • 2
  • 12
  • 23

1 Answers1

0

I think what your asking about is hash tag browsing.

jquery javascript: adding browser history back with hashtag?.

This example uses jquery but all you have to do is put an event when the link is clicked to update the page sounds like you have something like that already.

Change the URL in the browser without loading the new page using JavaScript

This example gives you a better idea of what you would do with just Javascript.

Now this will not when they load the page using the bookmark because there is no browser history but will work when using your pages.

<a href="#hashtag" class="loadpage" data-page="directory/name">
Community
  • 1
  • 1