Sisi Sajah
Sisi Sajah

Reputation: 231

Disable form find browser, if pressed Ctrl + F

How to disable form find browser, if pressed Ctrl+F and focus to element html

<div id='demo'>
    <form class="id5-text-find-form" id="id5-text-find-form">
        <input class="search" placeholder="Find..." type="text">
        <input class="reset" type="reset" value="x">
    </form>
</div>


<textarea id="area">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.   
</textarea>

css :

#demo {
    display:none;
}
#area {
    width:100%;
    height:200px;
}
kbd {
    border:1px solid grey;
    padding:4px;
}

jQuery :

$(document).keydown(function(e) {
    if ( e.ctrlKey && ( e.which === 70 ) ){
        $("#demo").show();
    }
})
$(".reset").click(function() {
    $("#demo").hide();
})

Image :

enter image description here

Fiddle Demo :

Upvotes: 1

Views: 1246

Answers (1)

stackoverfloweth
stackoverfloweth

Reputation: 6917

use e.preventDefault() within your keydown function to prevent default behavior

use $(".search").focus(); to set focus

$(document).keydown(function(e) {
    if ( e.ctrlKey && ( e.which === 70 ) ){
        $("#demo").show();
        e.preventDefault();
        $(".search").focus();
    }
})

https://jsfiddle.net/ycgdd1gd/2/

Upvotes: 4

Related Questions