I'm trying to detect hashchanged which works fine in every browser except chrome. For example, with this code:
if ("onhashchange" in window) {
alert("The browser supports the hashchange event!");
}
The statement is never executed in Chrome but works in Firefox. I've seen a jQuery hashchange plugin on GitHub but didn't have any luck with that either.
Any ideas?
Related
I need to tell a 3rd party site that my site integrates with when a tab is closing. This seems easy enough for Safari, Chrome & Edge but is not working in Firefox
function close_the_chat(){
fetch(`https://example.com/closethething`);
}
window.addEventListener('beforeunload', function(event) {
close_the_chat();
});
I have also tried the event onunload, but it does not work in firefox.
How can I include firefox for this functionality?
Currently trying to run a function through the window.addListener('unload') event. This is the code I am trying to run:
window.addEventListener('unload', this.returnToDashboard)
returnToDashboard():
location.href = './'
The event gets triggered on Firefox but does not work on Chrome. My Chrome Version is: Version 104.0.5112.79 (Official Build) (x86_64)
Not sure why it is not working on Chrome. Any insight would be appreciated on alternatives. Thank you.
Update:
According to the MDN docs I am supposed to be using pagehide event but that does not trigger for Chrome either.
ThereĀ“s a question asking for the same, but it doesn't have a satisfactory answer as I already tried it.
This is my code:
$(window).on("focus", function() {
doSomeFunction();
alert("I am here!");
});
I'm using window because document wasn't working even on chrome desktop, someone suggested using window here in stackoverflow and it works on desktop at least, but in chrome mobile is another case.
With firefox mobile I can switch tabs, press home and reopen firefox, press home, swipe close and reopen firefox and I get the alert message, with chrome none of those cases work.
Need to find a way to make it work on that browser, remember, it works on chrome and firefox desktop and firefox mobile but not on chrome mobile.
Thanks in advance
Got a solution, it's probably not the best but it works.
Aparently chrome mobile is not catching this event when is placed on .js files
so I just have to place it on a tag in my html document:
<script>
$(window).on("focus", function() {
doSomeFunction();
alert("I am here!");
});
</script>
In this case, it doesn't matter if doSomeFunction() is in the DOM or in a .js file, just make sure the focus event is in the DOM
my script reads something like this:
$(window).bind('popstate', function() {
//some code
//few more lines of code
});
This function works perfectly as intended in Chrome and Safari browsers. But Firefox for some reason ignores this function and does not work as intended.
Instead of using:
$(window).bind('popstate', function() {
//some code
//few more lines of code
});
You can use:
window.onpopstate = function() {
//some code
//few more lines of code
}
As firefox is using W3C defined rules for history API, so you have to use this for firefox and it works in chrome, safari and other browsers as well.
Note that just calling history.pushState() or history.replaceState()
won't trigger a popstate event. The popstate event is only triggered
by doing a browser action such as a click on the back button (or
calling history.back() in JavaScript).
Browsers tend to handle the popstate event differently on page load.
Chrome and Safari always emit a popstate event on page load, but
Firefox doesn't.
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/popstate
Are you saying Chrome and Safari fire the event on page load or when the browser's back button is clicked? If the former, it's because Chrome/Safari are out of compliance with the HTML5 specs => the event should never be fired on page load. Up-vote https://code.google.com/p/chromium/issues/detail?id=63040 to get Google to fix this.
Please do Check that if you have coded window.load() more than once OR have called .onload() more than one time. This probably may work for IE but not for Chrome and fireFox.
I have a problem on Chrome on Android OS.
I work with a html5 page with jQuery and javaScript.
I have select box , number input .. etc.
When i try to "click", I have:
var hitEvent = 'ontouchstart' in document.documentElement ? 'touchstart' : 'click';
on a input or select nothing happens.
However when i do an alert("something") everything starts working.
On every browser works ok (Safari , Chrome on iPad,iPhone... ; Firefox , Internet Browser on Android) but not Chrome on Android.
Do you have any idea on how to solve this problem?
Normally when everything works after you put an alert,
that means there is a problem in a asynchronous call.
What is happening is that the alert is giving time for the page to really load or an event to actually happen. when you don't put an alert, an action is happening before the event
(for example an element is being called before it is generated)
Search in this perspective.
If it's working in Firefox, it is by pure luck from the way firefox is rendering the page, but still you have to fix your error.