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
Related
I'm trying to create a "re-launch" button that should bring the user to an existing opened tab. So far, this is how it's implemented:
Using window.open() initially to create the tab and focusing to that tab using window.focus().
The relaunch button should basically call window.focus() and redirect to that tab.
This has been asked in $window.focus() doesn't work on existing tabs in iOS Safari but I'd like to get a more general overview on this question. I've looked everywhere but I couldn't find any lead to this question.
Apparently, it works in android browsers but I can't get it to work in ios browsers (safari, chrome). Does anyone have any clue about this issue?
This seems to be a bug in iOS browsers. As a workaround you may replace
focus() by a sequence of close() and open(...).
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
I have a site, created with a template, that works just fine on Chrome, Edge, Safari, etc... but in firefox it crashes. It's a thing with a JS code that animates the images in the home page. You can see what I'm talking about in www.andarescolombia.com
If you go to that site in chrome you'll see the images on the home page working fine, but on firefox they seem to get collapsed to the top of the container:
On Chrome:
On Firefox:
So the images collaps in firefox, but the other JS plugins are working just fine. I already tryed to contact the seller, but they just have a lousy customer support service.
Please help!!
just avoid using $. it should prevent your error from occuring in firefox.
On the other hand why do you want to trigger the scroll event on window.load ? Oo
just wrap the magic you're using inside a function and call it on load and on scroll. saves you a lot of headaches.
Ive made a simple project with html and jquery. It works great in all browsers except for safari on ipads. Since apple doesnt have a windows version of safari i cannot check if the error is explicitly for ipad but i think so.
The problem is the photoboxes wich get their width from the jquery, they dont appear at all on the ipad. Chromes developer tools device mode shows everything correctly and i have css queries that take care of smaller screens so its only the ipad thats the problem. I havent found any way to do a web debug on the ipad either. Its hard to give a code example due to i dont really know what the error is but i have a live demo you can check out. For you on ipads, its supposed to be photos before the winter background.
http://www.mj-bygg.se/ipad/default.aspx
I am also getting the same error on desktop Chrome on the first load. If I refresh, then the pictures load fine but on first visit to the link I only get the footer image (trees.)
On the first load, none of your jQuery heights/widths are being applied. No errors in the console and if I rerun the function it works as it should (without reloading the page.)
I suggest either pushing the script further down the page or using $(window).load(function() {}
instead of
$(document).ready(function() {}
That is the only thing I can assume is wrong if it fails first time but works with the page being cached.
I have seen many examples on using javascript to resize a browser window, but for me they all fail to perform that function in IE. I include my code to see if anything is wrong with it that I just don't see. The code works great in FF but that is not used at my location.
I am no javaScript expert, but I am no slouch either. If I were new to javaScript I would be hating it. I'm sure it has something to do with IE but I cannot explain it.
Any help would be great.
CODE:
//window.sizeToContent();
window.resizeTo(700, 700);
I read in the docs that sizeToContent will not work in IE but resize should. It is an incredibly simple statement.
This works for me in Internet explorer 8
<html>
<head>
</head>
<body>
<h1>Resized</h1>
<script>
window.resizeTo(400,400);
</script>
</body>
I did some testing in IE9 beta (that's the only version of IE that I have on this machine), and it seems that window.resizeTo does not work on the initial page load. It does work if you refresh the page. Also, it does work if you delay its execution:
setTimeout(function() {
window.resizeTo(200, 200);
}, 2000);
(at least in IE9 beta)
The "working" example with IE is working only because there are no more tabs on the window.
If the windows has other tabs loaded, then it DOES NOT work. It's a security measure of IE8 and higher.
If you need to resize your window, you will need to open a new window. And for that, you will need to make the user click a button with the window.open onclick event, otherwise any popup blocker will block it.
You won't be able to resize the window reliably with JavaScript. It's not possible in IE 7 with tabbed browsing enabled. It's also potentially annoying for the user.
This seems to be IE only.
If your window is a "dialog" like:
window.showModalDialog(url,...)
I found this hacky way to make it the right size:
<script type="text/javascript">
//window.resizeTo(1000, 790); //Will not work if its a dialog
window.dialogWidth = '1000px';
window.dialogHeight = '790px';
</script>