Solved

Keep popup window in focus - EASY.

Posted on 2004-10-14
14
467 Views
Last Modified: 2012-06-21
Hi,

I'm sure there is script out there to do this..

I have a page that has a simple link that opens is a new window..
<head>

<script>
function openWindow(url)
  {
      var w = window.open(url,"popupReport","width=460,height=450,resizable=yes");
      
        }
</script>
</head>


<a href="JavaScript:openWindow('window.asp')">View Basic data for:-(Click)</a>

What I want to do is when the smaller popup window appears it contains info that the user needs to fill out data on the main form so I want it to stay on top all the time until the user closes it.

At the moment if I click the main window the popup goes to the back and this can annoy the user as they have to go and find the window each time.


Many thanks

Stu
0
Comment
Question by:Pigdogmonster
  • 5
  • 5
  • 4
14 Comments
 
LVL 33

Accepted Solution

by:
sajuks earned 30 total points
Comment Utility
first page
function openWindow(url)
  {
     var w= window.open(url,"popupReport","width=460,height=450,resizable=yes");
     w.focus();
 
       }

in the second page (popup)have
<body  onBlur="window.focus();">
</body>
0
 
LVL 33

Expert Comment

by:sajuks
Comment Utility
0
 

Author Comment

by:Pigdogmonster
Comment Utility
thanks Sajuks,

I will try this:-


function showHelp(theUrl) {
   if (document.all) WinHandle = window.showModalDialog(theUrl,'arguments','dialogWidth=200,dialogHeight=400')
   else WinHandle = window.open(theUrl,'newwin','width=200,height=400,alwaysRaised');
}


How do I incorporate this with my existing code?

first page
function openWindow(url)
  {
     var w= window.open(url,"popupReport","width=460,height=450,resizable=yes");
     w.focus();
 
       }

in the second page (popup)have
<body  onBlur="window.focus();">
</body>
0
 
LVL 13

Expert Comment

by:cLFlaVA
Comment Utility
sajuks, fyi-

the body onblur event won't be your friend if you have a textbox or other form element in there.  As soon as you set focus to the text box, the body loses focus, and so re-sets focus to the body, thus never enabling the user to interact with the textbox.
0
 

Author Comment

by:Pigdogmonster
Comment Utility
yeah, just noticed that :-(

The popup window contains information that helps the user fill out the textbox's on the form.

It works great but its  shame you cant enter text on the other form.

Do you know if its possible?
0
 
LVL 13

Expert Comment

by:cLFlaVA
Comment Utility
The only and best way would be using the modal window, unfortunately it only works in IE.

I have not yet found a way to do this with JavaScript, after several attempts at solving this exact problem for many people.
0
 
LVL 33

Expert Comment

by:sajuks
Comment Utility

modal window would be the only possible way but as already pointed out in my second post its IE only.
cLFlaVA my bad i'd forgotten that it wouldnt be possible to enter in the popup. Thanks for the correction
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Pigdogmonster
Comment Utility
Thanks Guys,

Luckily for me this site will only run on IE so I dont have an issue with using any other browsers.

Do you have the syntax for a modal window?
0
 
LVL 33

Expert Comment

by:sajuks
Comment Utility

  if (document.all) WinHandle = window.showModalDialog(theUrl,'arguments','dialogWidth=200,dialogHeight=400')
   else WinHandle = window.open(theUrl,'newwin','width=200,height=400,alwaysRaised');

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/showmodaldialog.asp
0
 

Author Comment

by:Pigdogmonster
Comment Utility
hi guys,

Just tried the modal window and that has the same problem - when the popup windowis open you cannot complete any information on the other windows!!

Do you think there is any other way round this?
0
 
LVL 13

Expert Comment

by:cLFlaVA
Comment Utility
I don't understand.  Your original request was, how do I keep a popup window focused until the user closes it.  Now, you're saying you DON'T want the window to have focus constantly.  You instead want the user to be able to access the parent window.

You can't have both scenarios, you'll have to choose only one.
0
 
LVL 33

Expert Comment

by:sajuks
Comment Utility
a modal window is like a response window ( alert box ) . unless you dont specify some action it wil lremain . thats what you wanted wasnt it?
0
 

Author Comment

by:Pigdogmonster
Comment Utility
Hi gents,

My request has always been the same but I think I have used the incorrect terminolgy when describing exaclty what I want! :-]

To have a popup window that stays focused but you can still enter data in the main window.

I just didnt realise it would'nt be possible to have the popup "on top"  and have be able to complete data in the main window.

The popup window is soley for displaying information that helps the user fill in the main form.

So the popup wondow does not have to be in focus but just not go the the back when the user clicks in the same window.

Sorry for any confusion.
0
 
LVL 13

Assisted Solution

by:cLFlaVA
cLFlaVA earned 20 total points
Comment Utility
Nope, no way to keep the window on top while typing in another window behind it.  Best you can do is resize them and place them next to eachother.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now