Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8333575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:04:53+00:00 2026-06-09T03:04:53+00:00

I have the following code which works fine: // click on the button $(.btnHeaderSearch).click(function(event)

  • 0

I have the following code which works fine:

// click on the button
$(".btnHeaderSearch").click(function(event) 
{ 
    event.preventDefault();
    window.open('/search.aspx?phrase=' + $('.txtHeaderSearch').val());
});

It will open search.aspx in a new window/tab and the window/tab will have focus or will be infront of all other windows/tabs.

However, the following code not work:

// press enter key when textbox has focus to simulate button click:
$('.txtHeaderSearch').bind('keyup', function(e) {
    if ( e.keyCode === 13 ) { // 13 is enter key
        window.open('/search.aspx?phrase=' + $('.txtHeaderSearch').val());
    }
});

What happens here is that the window/tab does open, but it opens a window behind all other windows, or it opens a tab without giving the tab focus, so I end up remaining on the original page.

How do I get the enter key press to open a window/tab which behaves the same way as the button click above? i.e. I want both bits of code to open a window or tab which has focus instantly just as the click even currently does.

I’m getting this behaviour in IE8. It works fine in Google Chrome and I’ve not tried it on any other browser. Unfortunately, I need to get this to work in IE8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:04:55+00:00Added an answer on June 9, 2026 at 3:04 am

    From http://msdn.microsoft.com/en-us/library/ie/ms537632(v=vs.85).aspx:

    Ensure that all of the pop-up windows in your Web site open as the
    direct result of a user action, such as clicking a page element, or
    tabbing to a link and then pressing ENTER.

    In fact your code didn’t work for me at all, the IE default popup blocker just blocked it. I consider that unacceptable since most users would not allow it.

    I worked around it by moving the focus to a hidden link (same as tabbing to it) when enter is pressed down (important as it’s too late after keyup), and when it is released it will be the same as pressing enter while on that link so the popup opens.

    HTML:

    <input class="txtHeaderSearch">
    <a id="hidden-link" href="#">needs to have content</a>
    

    CSS:

    #hidden-link {
        position: absolute;
        left: -9999px;
        top: -9999px;
    }
    

    Javascript:

    $('.txtHeaderSearch').bind('keydown', function(e) {
        if (e.which === 13) { // which is normalized by jQuery
            $("#hidden-link").focus();
        }
    });
    
    $("#hidden-link").click(function() {
        var win = window.open('/search.aspx?phrase=' + $('.txtHeaderSearch').val());
        //win.focus(); 
        //The above is optional, if the window opens but doesn't focus then uncomment the above line
    });
    

    Demo:

    http://jsfiddle.net/UCcqM/2/

    This same workaround doesn’t work for other browsers, so you need to detect IE and conditionally use the appropriate solution depending on the browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code, which works fine: $(document).ready(function () { $('#link1').click(function ()
I have the following jquery code which works fine. $('#onlyTwo').click(function() { $(#textarea3).attr(disabled, true); $(#textarea4).attr(disabled,
I have the following code, which works fine: <input type=button name=btnHello value=Hello onclick=Test();/> and
At the moment I have the following code which works fine. label = new
I have the following code which works perfectly fine, however I would like to
I have the following code for Android which works fine to play a sound
I have the following block of code which works fine; var boughtItemsToday = (from
I have the following line of code which works fine locally, but breaks when
I have the following code, WHICH WORKS JUST FINE...WORKS AS I WANT. But if
I have the following jQuery code: $(body.page-calendar-practices-2012-05 #content-header h1#title) which works fine. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.