Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does history back not work on <a> onclick in Firefox?
    primarykey
    data
    text
    <p>I don't understand why in Firefox, <code>window.history.back()</code> does work on a button:</p> <pre><code>&lt;button onclick="window.history.back()"&gt;Go back&lt;/button&gt; </code></pre> <p>But it does not work for a link:</p> <pre><code>&lt;a onclick="window.history.back()"&gt;Go back&lt;/a&gt; </code></pre> <p>What is the difference?</p> <p>An example illustrating this:</p> <p><strong>index.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;First page&lt;/h1&gt; &lt;br/&gt; &lt;a href="second.html"&gt;Second&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>second.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;Second page&lt;/h1&gt; &lt;a href="third.html"&gt;Third&lt;/a&gt; &lt;br/&gt; &lt;br/&gt; &lt;button onclick="window.history.back()"&gt;Go Back (button)&lt;/button&gt; &lt;br/&gt; &lt;a href="javascript: void(0);" onclick="window.history.back()"&gt;Go Back (a)&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>third.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;Third page&lt;/h1&gt; &lt;br/&gt; &lt;button onclick="window.history.back()"&gt;Go Back (button)&lt;/button&gt; &lt;br/&gt; &lt;a href="javascript: void(0);" onclick="window.history.back()"&gt;Go Back (a)&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Scenario:</strong></p> <ol> <li>Run index.html and click <strong>Second</strong>.</li> <li>On second.html click <strong>Third</strong>.</li> <li>On third.html click <strong>Go back (a)</strong>.</li> <li>On second.html click <strong>Go back (a)</strong>. Boom! I'm on the third.html, and not on the first.html!!!</li> </ol> <p><strong><a href="http://plnkr.co/edit/erszqHsAkmk0yR1quzYB?p=preview" rel="noreferrer">Plunker example</a></strong> (Note! Run it on Firefox)</p> <p>If you use <strong>Go back (button)</strong> it works. What is the difference in <code>&lt;a onclick</code> and <code>&lt;button onclick</code> in this case?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload