9

I'm using modal from bootstrap 3 where it contains on input field

this modal is being launched using jquery code when page is loaded (not by clicking a button)

$().ready(function()
{
    $('#OTPModal').modal('show');
});

once the modal is shown I'm making the input become focus by this code

$('#OTPModal').on('shown.bs.modal', function () 
{
    $('#OTPField').focus();
});

this code is working fine in google chrome, but it's not in firefox !

check the jsFiddle with chrome and firefox to see the different

https://jsfiddle.net/aq9Laaew/272015/

firefox version: 63.0.1 (64-bit)

chrome version: Version 70.0.3538.77 (Official Build) (64-bit)

sulaiman
  • 311
  • 2
  • 3
  • 11
  • Do you want the modal to open automatically when the page is opened or just when the button is pressed? – Adrian Pop Nov 18 '18 at 11:12
  • Actually, if you add these next lines: `var focused = document.activeElement; console.log(focused);` after `$('#OTPField').focus();`. Then you can see that the input is currently focused. It is very strange, I have tried a few things, but none had worked. – Shidersz Nov 19 '18 at 20:25
  • @Adi I want to make it automatically opened and automatically focused – sulaiman Nov 22 '18 at 07:52
  • @D.Smania I think firefox it self needs to do something in their browser to fix this issue. I don't believe there is anything from the javascript side to be done. – sulaiman Nov 22 '18 at 07:53
  • @sulaiman Have you tested this on a local environment (server), without Snippet or Fiddle framework? Just to be sure, because I have tested auto focus on an input element when document is ready on my local environment and it works (with Firefox), but this same don't work inside Fiddle or Snippet. I know is not the actual same problem (because yours use a modal) but you should give it a try if you not already do it. – Shidersz Nov 22 '18 at 15:23
  • 2
    This code works perfectly fine in Firefox if you just run it locally. – Katie.Sun Nov 23 '18 at 22:57
  • The problem exists within BS3, BS4 works just fine – gavin Nov 24 '18 at 06:35
  • 1
    If you see the fiddle directly http://fiddle.jshell.net/aq9Laaew/272015/show/ the example works just fine in firefox. – Niebieski Nov 24 '18 at 10:39
  • Possible duplicate of [jQuery Focus fails on firefox](https://stackoverflow.com/questions/7046798/jquery-focus-fails-on-firefox) – Alexander Nov 27 '18 at 04:13

1 Answers1

0

this problem is from fiddle site in firefox. see your code without fiddle iframe. https://fiddle.jshell.net/aq9Laaew/272015/show/

saeid mohammad hashem
  • 1,271
  • 1
  • 15
  • 19