Awesome q2a theme

How to make the autofocus on the input field on one page only?

0 like 0 dislike
22 views
Good day.

I wanted to do. below the search form on the website was active, but
  • only on the main page
  • only in the PC version of the site


Used this script:

if(window.location.toString().indexOf('site.ru') > 1) { $(window).resize(function() { width = $(window).width(); if (width >= 991) { { $("#search").focus(); }; } }); };


Everything works, except for restrictions on one main page. If on the test site to point to a string
if(window.location.toString().indexOf('site.ru\\index.php') > 1)

then it works, but on combat project is the redirect virus: removed index.php and trailing slash, so the script runs on all pages. What can I do?
by | 22 views

3 Answers

0 like 0 dislike
There are also location.pathname!
by
0 like 0 dislike
On mobile phone, typically has a touchscreen.
I usually check for touch handlers.
And no matter what device: Apple, Android, etc.
if ('ontouchstart' in document.documentElement) { // have a touchscreen, so dealing with a portable gadget. } else { // desktop version of the code (an input element).focus(); //set focus }
by
0 like 0 dislike
Else can directly on the server to add the attribute autofocus when you return the main page.
To detect cell phone by using different libraries.
For php for example mobiledetect.net
by

Related questions

0 like 0 dislike
1 answer
asked May 22, 2019 by sdgroup14
0 like 0 dislike
1 answer
0 like 0 dislike
6 answers
0 like 0 dislike
3 answers
0 like 0 dislike
4 answers
110,608 questions
257,187 answers
0 comments
40,796 users