Why Firefox always jumps to start of page after opening another page in the same window and getting back?
Re: Firefox 57 (Quantum)
I try to use two classic JavaScript methods of opening a URL: 1) window.location = URL 2) window.open(URL} After executing one of these commands, FF opens the URL, OK, but when I return to the previous page (with Backspace or, "Back" arrow), FF always jumps at the top of the page, whereas the page had been scrolled down. In fact, I can see for a fraction of a second the FF already jumps at the top of the page instantly after clicking on the link (i.e. before even bringing up the new URL)!
Note that Internet Explorer behaves as expected, i.e. it keeps the last position where the link was clicked on, with the same HTML file! So it is definitely a FF bug. Can it be repaired?
All Replies (11)
Hello, to file a bug report - head on over to https://bugzilla.mozilla.org and create an account - Once registered follow the documentation for bug filing to get started.
This can happen when the website instructs Firefox not to cache the page. When this happens then Firefox won't be able to return to the previous position. Best in such cases is to open other pages in a new tab (middle-click or via the right-click context menu). Then you can close the tab to return to the original page.
What website, cache and all that stuff ? Didn't you read my description? Please do next time. It's a simple HTML file. I also included a screenshot. And no, opening the links to a new TAB is far from a solution! Imagine what a pain this is if you check a list of a lot of links. Again, see the screenshot I included; I didn't do that for nothing. Think also of checking links in Google results!
Is this a new issue in Firefox 57 that you didn't notice in Firefox 56?
What is your code? If you are attaching it to a link, make sure to cancel the default action of the link:
POTENTIALLY PROBLEMATIC:
<a href="#" onclick="window.open('someurl.html');">
SAFER:
<a href="#" onclick="window.open('someurl.html'); return false;">
Yes, this works. But then, one has to write the whole absolute address for each link, so what's the use? There's no need for a JS script then. The JS script helps exactly to avoid writing the same base URL stupidly hundreds of times!
Modified
I think a long time ago it used to work in the script, but it's difficult to remember. Maybe it works in the script if you target window.open() to a new window or named window, but not the same tab? I can't recall testing that recently.
There are always little optimizations being made to the code that don't make the release notes.
Go ahead and search for or file a new bug if Firefox is inconsistent.
I have modified my reply, sorry. Please read what I realized your suggestion involves, even if it solves the "jumping-to-the-top" problem. Thanks anyway!
I don't understand your edited reply. Where is your test page demonstrating this problem? Please give a link.
How to explain better? Well, you suggest doing the following:
<a href="#" onclick="window.open('someurl.html'); return false;">
Right? Well, if 'someurl.html' contains an absolute base ref (e.g. https://support.mozilla.org/en-US/questions/ plus the page name, '1192073') and I have to create 1000 such links (with the same absolute base ref) I could well use directly
<a href="someurl.html">
That's why I am asking, what's the use? A JavaScript in this case serves to automatically add the absolute base ref to the page name, so that you don't have to write it in each href. This is a very common practice used e.g. in loading images from a common path. Is it clear now?
I understand my example. What I don't understand is what's going wrong on your page. Can you post a link to a page demonstrating the problem? If you plan to file a bug, you will want to provide a minimal test case demonstrating which links works and which don't to show that Firefox is inconsistent. Might as well give me the link now.
What link??? It's a simple, local HTML file. Besides, I have attached screenshots (compiled into a single image).