1

I'd like to modify the enter key to fire off a window.open(ui.item.url)

Could someone help me do this? The autocomplete key code block is here:

.bind( "keydown.autocomplete", function( event ) {
if ( self.options.disabled ) {
    return;
}

var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
    self._move( "previousPage", event );
    break;
case keyCode.PAGE_DOWN:
    self._move( "nextPage", event );
    break;
case keyCode.UP:
    self._move( "previous", event );
    // prevent moving cursor to beginning of text field in some browsers
    event.preventDefault();
    break;
case keyCode.DOWN:
    self._move( "next", event );
    // prevent moving cursor to end of text field in some browsers
    event.preventDefault();
    break;
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
    // when menu is open or has focus
    if ( self.menu.element.is( ":visible" ) ) {
        event.preventDefault();
    }
    //passthrough - ENTER and TAB both select the current element
case keyCode.TAB:
    if ( !self.menu.active ) {
        return;
    }
    self.menu.select( event );
    break;
case keyCode.ESCAPE:
    self.element.val( self.term );
    self.close( event );
    break;
default:
    // keypress is triggered before the input value is changed
    clearTimeout( self.searching );
    self.searching = setTimeout(function() {
        // only search if the value has changed
        if ( self.term != self.element.val() ) {
            self.selectedItem = null;
            self.search( null, event );
        }
    }, self.options.delay );
    break;
}
})

2 Answers 2

1

I added a if block to the success method so that if the keypress == 13 I just open a new window with the url and return

Sign up to request clarification or add additional context in comments.

Comments

0

I assume you're experiencing trouble with popup-blockers.

If that's the case, then you should know that browsers will block popups that weren't triggered directly by a user-interaction. Usually this means a mouse-click is required, although I'm not entirely certain whether an enter-key trigger will be blocked. You may want to open the window and then change the location of the window after the window is loaded.

var newWin = window.open(null, 'name');
newWin.onload = function(e)
{
  newWind.location = url;
}

you may need to set up an onReadyStateChange event for IE instead of the onload event.

jQuery has some issues when working in the context of a different window, so be certain to check what window reference you're using, else your global vars might disappear.

1 Comment

The current behavior of the enter key is to place the value into the input box. I want to modify the behavior to instead preform a window.open(ui.item.url) I didn't mention anything about popup lockets but thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.