Set focus mouse

This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30352
    joolsscott84
    joolsscott84
    Participant

    dear Ernest,

    i wondered if you could suggest how to make the focus of the keyboard automatically set on the Ajax Search Pro bar when my site loads up?

    I found this article (with you offering solutions in it!) on wordpress.org
    https://wordpress.org/support/topic/trying-to-automatically-set-focus-in-the-search-box/

    For my site, the search is the main feature – to find a catalog of 900 pages.

    BTW your plugin, which I bought the full version today) is just amazing. It has solved many of my problems. That combined with a WP Sheet Editor Spreadsheet is just the most incredibly sophisticated search database.

    Any help would be appreciated.

    • This topic was modified 2 years, 6 months ago by joolsscott84 joolsscott84.
    #30353
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you for the details!

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_action("wp_footer", "asp_custom_script_wp_footer");
    function asp_custom_script_wp_footer() {
    	?>
    	<script>
    	var inv;
    	jQuery(function($){
    		inv = setInterval(function() {
    			if ( typeof ASP != "undefined" && ASP.initialized ) {
    				$('input.orig').focus();
    				clearInterval(inv);
    			}
    		}, 500);
    	});
    	</script>
    	<?php
    }

    I could not test this, so please be careful.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #30355
    joolsscott84
    joolsscott84
    Participant

    You are amazing! that worked first time.

    I will make a child theme so it doesn’t get lost when i update.

    Many thanks Ernest. I will leave a review on WP and CC

    #30356
    joolsscott84
    joolsscott84
    Participant

    One last thing (upon testing)

    Can you think of any way to make this work only on the homepage?

    i have a search box on each post and this new code currently takes the focus to the bottom of the page.

    Thanks again

    #30358
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are welcome, and thank you for your kind words. Maybe, I think the is_home() might do it.

    add_action("wp_footer", "asp_custom_script_wp_footer");
    function asp_custom_script_wp_footer() {
    	if ( is_home() ) {
    		?>
    		<script>
    		var inv;
    		jQuery(function($){
    			inv = setInterval(function() {
    				if ( typeof ASP != "undefined" && ASP.initialized ) {
    					$('input.orig').focus();
    					clearInterval(inv);
    				}
    			}, 500);
    		});
    		</script>
    		<?php
    	}
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #30361
    joolsscott84
    joolsscott84
    Participant

    That seems to have broken the script, it doesn’t work on home either now.

    Sorry to take up your time!

    If we can’t work it out I will go back to how it was originally.

    Thanks Ernest! Really appreciate your help

    #30363
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Maybe this variation then:

    add_action("wp_footer", "asp_custom_script_wp_footer");
    function asp_custom_script_wp_footer() {
    	if ( is_front_page() ) {
    		?>
    		<script>
    		var inv;
    		jQuery(function($){
    			inv = setInterval(function() {
    				if ( typeof ASP != "undefined" && ASP.initialized ) {
    					$('input.orig').focus();
    					clearInterval(inv);
    				}
    			}, 500);
    		});
    		</script>
    		<?php
    	}
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.