Simulate history.go(-1) with Javascript/JQuery : <p>I have three different html files (<strong>page1.html</strong>, <strong>page2.html</strong>, <strong>page3.html</strong>) that each contain a link to the same target in a fourth html file (<strong>glossary.html</strong>).</p>

<p>For technical reasons, I can't use <strong>history.go(-1)</strong> or other brower-specific functions, but I can use JavaScript and JavaScript libraries, e.g. JQuery, and LocalStorage.</p>

<p>What would be the best way to mimic the functionality of <strong>history.go(-1)</strong> with JavaScript?</p>

<p>The technical details are as follows:</p>

<p><strong>page1.html</strong> contains the following link:</p>

<pre><code>&lt;a id="page1" href="glossary.html#def1" class="footnote"&gt;1&lt;/a&gt;
</code></pre>

<p><strong>page2.html</strong> contains the following link:</p>

<pre><code>&lt;a id="page2" href="glossary.html#def1" class="footnote"&gt;1&lt;/a&gt;
</code></pre>

<p><strong>page3.html</strong> contains the following link:</p>

<pre><code>&lt;a id="page3" href="glossary.html#def1" class="footnote"&gt;1&lt;/a&gt;
</code></pre>

<p><strong>glossary.html</strong> contains the following link:</p>

<pre><code>&lt;a id="fn1" href="#"&gt;↵ Back &lt;/a&gt;Term 1: Definition of term one.
</code></pre>

<p>I.e., the script(s) should do the following:</p>

<ol>
<li><p>Retrieve the id of the calling html page (<strong>page1</strong>, <strong>page2</strong> or <strong>page3</strong>) and save it as a LocalStorage item or in another suitable persistent manner.</p></li>
<li><p>When the user clicks the <strong>↵ Go back</strong> link, the href of the definition in glossary.html needs to be updated so that it points to <strong>page1.html#page1</strong>, <strong>page2.html#page2</strong> or <strong>page3.html#page3</strong>, depending on the html page that the glossary link was clicked on. </p></li>
</ol>

<p>What would be the easiest way to solve this problem?</p>
