After travelling back in Firefox history, JavaScript won't run
Set an empty function to be called on window.onunload:
window.onunload = function(){};
e.g.
<html><body>
<script type="text/javascript">
window.onload = function() { alert('window.onload alert'); };
window.onunload = function(){};
alert('inline alert');
</script>
<a href="1.html">Click Me!</a>
</body></html>
Source:
http://www.firefoxanswer.com/firefox/672-firefoxanswer.html (Archived Version)
Javascript: run script even after back button on same page with different anchor
If you are not reloading the page you can do this with an event listener.
window.addEventListener('hashchange', function () {
// do stuff
});
Why does history back not work on a onclick in Firefox?
You are facing this issue (quoted from vikku.info):
But what had happened when i press the back button after navigating to
various pages was i got locked between the last two navigated pages.
Someone in the comments hit the nail on this issue.
- When you create the
onclick
attribute, you are attaching an additional event handler for clicking a link. However, the browser will still handle some native logic, so it will still add the current page to the history; - When you pass in specific javascript into the
href
attribute, you are actually overriding the native logic of the browser, so it won't add the current page to the history;
SIMPLE, DIRTY SOLUTION
HTML:
<a href="javascript:window.history.back();">Back</a>
IMPROVED SOLUTION
I've also created an example (Plunker example) that makes use of the native preventDefault
functionality (MDN on preventDefault). In that case, it is not needed to write javascript in the href
attribute. Now, you can support users that are not using javascript by linking to, for example, the homepage. You better also avoid using inline event handlers.
HTML:
<a href="index.html" id="backButton">Back</a>
Javascript:
var backbutton = document.getElementById("backButton");
backbutton.onclick = function(e){
e = e || window.event; // support for IE8 and lower
e.preventDefault(); // stop browser from doing native logic
window.history.back();
}
firefox browser back button doesn't refresh the page
I doubt that your code works, I cannot see how it will ever reach the else
because onload
happens only once at page load, and reload
will call it again on the next page load. To prevent the back button, you can use window.onbeforeunload
.
More details here : how to stop browser back button using javascript
When I press the browser back button or mouse back button the Javascript seems to be cached in Wordpress and it doesn't execute the code
If anyone else is running into this problem; I have fixed it by adding
window.onunload = function(){}; to the first line of the file, as suggested in After travelling back in Firefox history, JavaScript won't run. Thanks to mplungjan for taking the time to look into the issue with me!
Form fields in firefox not remembering entered data as it should after pressing the back button
There is no specific behaviour that is expected. There is no standard for this behaviour, so there is no definite right or wrong.
Firefox is simply more restrictive when repopulating the fields. When the order of the fields doesn't match how the page looked when you left it, it obviously stops trying to match the fields with the previous data.
The other browsers that you mentioned seems to be more relaxed in how they repopulate the fields. That of course also means that there is a higher risk for them to put the wrong information in the fields in certain situations.
You can reduce the risk for differences in behaviour by only adding fields last, but as long as you add fields using client script, you can't rely on all browsers behaving the same.
Related Topics
React - Prevent Event Trigger on Parent from Child
Jquery .Animate() Stop Scrolling When User Scrolls Manually
React Inline Style - Style Prop Expects a Mapping from Style Properties to Values, Not a String
Confusion About Node.Js Internal Asynchronous I/O Mechanism
How to Declare Hash.New(0) with 0 Default Value for Counting Objects in JavaScript
How to Raw Url Encode/Decode in JavaScript and Ruby to Get the Same Values in Both
How to Get the Position of Element Transformed with CSS Rotate
Tool for Checking Unused CSS Selectors
CSS Float Elements with Unequal Heights Left and Up in Grid
Transforms Are Added...Endlessly
Show Dynamically Added Navlinks When Added in Bootstrap Navbar
Changing Pseudo-Element Style from JavaScript
Using JavaScript to Detect Google Chrome to Switch CSS
How to Get CSS3 Multi-Column Count in JavaScript
HTML Mobile -Forcing the Soft Keyboard to Hide
Http Head Request in JavaScript/Ajax
How to Add "Href" Attribute to a Link Dynamically Using JavaScript