Solved

Keep focus on window

Posted on 2011-03-23
4
667 Views
Last Modified: 2012-05-11
Hi,

Given the following example, how do i keep the focus on the current page after a user clicks on the link. In other words the link should open but the focus should remain on the current page.
I tried using the window.focus function but for some reason this does not work.

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
KEEP ME IN FOCUS<BR>
<A HREF="http://www.google.com" TARGET="_blank">Link</A>
</BODY>
</HTML>

Open in new window


Any help would be appreciated.

Kind regards,
Nebu
0
Comment
Question by:Nebukad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 35197785
<html>
    <head>
        <title>test</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <style type="text/css">
        </style>
        <script type='text/javascript'>
            $(function(){                 
               $('a').click(function(){
                   window.open(this.href)
                   $(window).focus();
                
                   return false;
               })
            });

        </script>
    </head>
    <body>
        <a href="http://www.google.com" target ="_blank">location</a>
    </body>
</html>

Open in new window

0
 

Author Comment

by:Nebukad
ID: 35198064
Thanks for your response darren-w but unfortunately this does not work.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 50 total points
ID: 35198595
>but for some reason this does not work

for security purpose

check if you like this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<A HREF="http://www.google.com" onclick="window.open(location.href);">Link</A>
</body>
</html>

Open in new window

0
 
LVL 13

Accepted Solution

by:
darren-w- earned 450 total points
ID: 35198643
This opens a window, but keeps the parent in focus

<html>
    <head>
        <title>test</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

        <script type="text/javascript">
            <!--
            function popitup(url) {
                newwindow=window.open(url,'name','height=600,width=800');
                if (newwindow.focus) {window.focus()}
                return false;
            }

            // -->
        </script>
    </head>
    <body>
        <a onclick="return popitup(this.href)" href="http://www.google.com" target ="_blank">location</a>
    </body>
</html>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question