I can't seem to get element.focus({preventScroll:true});
to work in Chrome although it's working perfectly in IE11. Has anyone else experienced this? Using this in Chrome results in the element not becoming focused at all.
Asked
Active
Viewed 5,986 times
1

Alien
- 444
- 2
- 9
- 28
-
Have you tried `preventScroll:true` as seen in [this example](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#Focus_prevent_scroll)? – showdev Feb 07 '19 at 19:03
-
1@showdev yes, sorry my code is actually `element.focus({preventScroll:true});` -- I'll update my question. Thanks! – Alien Feb 07 '19 at 19:06
-
Can we see your complete code? I'll give it a try in Chrome. – showdev Feb 07 '19 at 19:10
1 Answers
1
It probably has to due with focus issues in chrome
If you run the focus code for buttons from the example in the docs here in Chrome vs Firefox, you'll see the difference.
you can try:
window.setTimeout(function ()
{
document.getElementById('element').focus({preventScroll:true});
}, 0);
However without more code its hard to debug a solution for you.

brietsparks
- 4,776
- 8
- 35
- 69

cb64
- 825
- 8
- 16