Skip to content Skip to sidebar Skip to footer

How To Make The Page Script Recognize A Manually Changed Value Of Input Element?

I'm working on a Chrome extension and am currently trying to get my content script to automatically do a search using the form on the site. I'm doing this by changing the value of

Solution 1:

I can't say without seeing the actual page but it's possible the page checks if the input was "typed", which we can simulate by using document.execCommand:

document.getElementById('videoSearchInput').focus();
document.execCommand('selectAll');
document.execCommand('insertText', false, 'some text');

Or, if you use jQuery, register a new function:

(function( $ ) {
    $.fn.execInsertText = function(text) {
        var activeElement = document.activeElement;
        var result = this.each(function() {
            this.focus();
            document.execCommand('selectAll');
            document.execCommand('insertText', false, text);
        });
        if (activeElement) {
            activeElement.focus();
        }
        return result;
    };
}( jQuery ));

then invoke it:

$("#videoSearchInput").execInsertText('herpderp');

Post a Comment for "How To Make The Page Script Recognize A Manually Changed Value Of Input Element?"