Javascript New Window and Focus

Posted on 2002-06-17
Last Modified: 2012-08-13
I want to be able to open a second window when I click on a link and have the second window take the focus. (usually happens by default)

When the user returns to the first window without closing the second and clicks on another link, I want that link to open in the second window and take the focus.

I can do all of this except for the second window taking the focus when the second link is clicked.

Here's what I've got right now:


<P><A HREF="firstpage.html" TARGET="myWindow">First Page</A></P>
<P><A HREF="secondpage.html" TARGET="myWindow">Second Page</A></P>
Question by:bhlang
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
  • 4
  • 2
LVL 33

Expert Comment

ID: 7084181
there are two ways to do it ...
in both firstpage.htm and secondpage.htm, do this:

<BODY onLoad='self.focus();'>
LVL 33

Expert Comment

ID: 7084188
the second way is to try to do it in the link:

<P><A HREF="firstpage.html" TARGET="myWindow"
   onClick=';return false;'>First Page</A></P>
<P><A HREF="secondpage.html" TARGET="myWindow"
   onClick=';return false;>Second Page</A></P>

Author Comment

ID: 7084189
That wshuld work fine in most cases. I should have mentioned that firstpage.html and secondpage.html MAY be PDF documents instead of HTML documents. What would I use on those when the Acrobat plug in is set to open the documents in the browser instead of in the application?
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

LVL 33

Accepted Solution

knightEknight earned 100 total points
ID: 7084196
oops, forgot the target:

<P><A HREF="firstpage.html" TARGET="myWindow"
  onClick=',;return false;'>First Page</A></P>

<P><A HREF="secondpage.html" TARGET="myWindow"
  onClick=',;return false;'>Second Page</A></P>

LVL 33

Expert Comment

ID: 7084198
ok, if they are PDFs, then try the method above instead.

Author Comment

ID: 7089900
It worked as promised! Thanks

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

705 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