2

When testing the following code in Google Chrome version 36.0.1985.49 on an iPhone 5 running iOS 7.0.6, it always alerts BODY even when focused on the input element, but it should alert INPUT. Would there be any way to get the focused element cross-browser without tracking every focus and blur?

HTML:

<input type="text">

JS:

setInterval(function () {
    alert(document.activeElement.tagName);
}, 5000);


Fiddle

Also, $(':focus') just gives no result for mobile chrome because it probably ignores when document.body is the focused element.

Mobile Safari works exactly as it should.

Non-Duplicates:

Community
  • 1
  • 1
Anonymous
  • 11,748
  • 6
  • 35
  • 57
  • 1
    Don't have an iPhone, but this code exactly as written works on Android (just FYI). – Michael Jul 25 '14 at 02:28
  • Good to know. It seems very strange that it doesn't work on just mobile Chrome of all browsers, so I figured there must be some way around it. – Anonymous Jul 25 '14 at 02:29
  • 1
    Well, Chrome for iOS isn't allowed to use Safari's Nitro rendering engine...rather, Chrome just uses webkit with a Chrome UI (https://developer.chrome.com/multidevice/ios/overview). Therefore, Chrome on iOS isn't really Chrome, it just looks like Chrome. If no one else can provide an answer, I might submit this as a bug to Google (should be able to through the settings menu in iOS Chrome). – Michael Jul 25 '14 at 02:34
  • @Anonymous You're going to have to tell us what versions of iOS and Google Chrome you have, because I have an iPhone 5 running on iOS _7.1.1_ with Chrome _36.0.1985.49_ and it [**works perfectly**](http://shrt.tf/1x). – blex Jul 27 '14 at 21:27
  • @blex Good point, updated. I guess it was fixed with an iOS update, but I still wonder if there would be an easy way around it. – Anonymous Jul 27 '14 at 21:54

1 Answers1

3

JSfiddle was blocking the input element on mobile chrome with another element above it, so it was never actually focused. It just looked focused.

Anonymous
  • 11,748
  • 6
  • 35
  • 57
  • hang on you only had this error in jsFiddle you did not try it using a web site first then moving to jsFiddle you know jsFiddle is more for debugging help – Barkermn01 Jul 30 '14 at 12:23
  • @Martin No, that would be ridiculous. The problem was that when I tested it on my website with the full code first, there was an actual chrome bug that I have reported that made it seem like the same problem. – Anonymous Jul 30 '14 at 12:32
  • you should not have answered this your self then you should have closed the question if it was due to a bug in the browser, or at least put in your answer that the problem was a bug in chrome not just it was a problem with jsFiddle this makes it look like the problem was jsFiddle and if another user was to have this problem and comes from google there going to go what im not using jsFiddle, (i'm not having ago i'm just trying to help users who find this page will understand the problem) – Barkermn01 Jul 30 '14 at 14:23
  • 1
    This problem **was** due to a problem in JSfiddle. A different but related problem was due to a Chrome bug. I'll just delete the question. The odds of someone else having this problem are probably not high plus it prevents people from thinking I am still looking for an answer to award bounty to. – Anonymous Jul 30 '14 at 14:25