I have this simple code on a page
$(document).ready(function () {
alert(“works”);
});
Then I go to the next page, I click in the browser back button and it doesn’t fire the $(document).ready, but if I return to previous page by a link it does.
Tested on desktop browsers and no problem but doesn’t work on Safari or Chrome on IPad
Any idea?
Thanks in advance
Related
So I have an element and when I click on that, it will toggle open and close.
$(document).on("click","#element",function(){
doSomething();
});
So this was not working on an iPad and I searched for the issue on this forum and found different solution and most common one was to add touchstart. So I did that. My code is now:
$(document).on("click touchstart","#element",function(){
doSomething();
});
Now after adding this I am able to click on the iPad. But on desktop, it seems that it is clicking twice. So if I am clicking, it is opening and closing at the same time.
So I the added preventDefault function:
$(document).on("click touchstart","#element",function(e){
e.preventDefault();
doSomething();
});
Now, Chrome is working good on both iPad and Desktop. Mozilla is good on Desktop but Mozilla on the iPad is same, clicking twice effect.
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
I have code what should detect mobile devices and do my code, if it mobile device (below regex) which contain cookie check and if it absent popup div with buttons which gives cookie when clicked.
But in mobile browser (android) and firefox when i click on button which should give cookie and hide div NOTHING HAPPENS. But in jsfiddle function which hide div works fine, in browser on my site - no. Yep i have jquery included in my page. I'm dissapointed, please help. I'm new in JS and sorry for my english
Function for hide div
hide_ask_div = function(){
$('#ask-user').hide();
}
jsfiddle with mobile devices check
jsfiddle with no mobile devices check, just for test
After logout browser should not allow to go back when user clicks on browser back button. This functionality is working fine in IE, FF but not working in Safari. Tryied a lot but not able to solve. Here is the code that i have used.
$(document).ready(function(){
window.location.hash="";
window.location.hash="";
window.onhashchange=function(){
window.location.hash="";
}
});
You can Disable safari browser back button if above trick is not working for you.
try this to disable back button-
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
Ive used the following javascript to hide the browser chrome for mobiles by scrolling down the page just enough that its out of view. It works fine for iPhone but does nothing on the first android ive tested with.
$(document).ready(function () {
window.scrollTo(0, 0);
}
Maybe you need to put more than 0 scroll. I think this will work.
window.scrollTo(0,1);