...

View Full Version : How to I set focus to a new window?



limshady411
08-19-2005, 11:16 PM
Hi,

I am trying to create a popup window to open a custom page and keep focus until the user forces it to close by clicking a close link. I created the following function and then I call it:

function topWindow()
{
popup = window.open('test.htm','Testing','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb ars=no,resizable=no,width=400,height=200,left=350,top=200'); return false;
}

I call it in an IF statement within another function:

if (count<1)
topWindow();

My custom page has the following in the body tag:

<body onload="windows.focus()" onBlur="self.focus()">

When I test this, sometimes it stays on focus, but other times, it is moved behind the main page, which I don't want. I want it to popup over the main page and the close it in order to continue navigating.

Any suggestions? I was thinking of an if statement that if it doesn't have focus, put focus back on it, but I'm not sure of the syntax for that and if it is possible. Thanks!

martin_narg
08-20-2005, 12:05 AM
Remove all the other code in the body tag, and loops, etc and just have this to make sure the popup appears in front when it loads:


function topWindow() {
var popup = window.open('test.htm','Testing','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb ars=no,resizable=no,width=400,height=200,left=350,top=200');
popup.focus();
}

There is a way to always keep the popup in front of the window that opened it but users shouldn't be forced into this functionailty - it's a bad idea to impede the users, and that would really irritate users - I know it would annoy me!

JavaScript should be used to enhance, not impede the interactivity of the page. Don't forget that users can simply switch off JavaScript or not revisit the site again if they feel the scripts are not doing them any favours.

Hope this helps.

m_n

limshady411
08-22-2005, 06:42 AM
Thanks for your response. Well, originally, I had code for an alert to do this (which required the user to click ok), but that was causing another issue. So I was trying to come up with a similar alternative for my alert, which would be a new window with the same message and similar closing option as the alert. I know it's annoying, but I'm only making the code per a request of the project. It's on the Intranet and that's what the project team is aiming at. What do you think? Thanks.

jscheuer1
08-22-2005, 07:25 AM
If it is an intranet and all the browsers will be IE, there is a special type of popup that has just those properties:



Modeless dialog box. The modeless dialog box allows a user to interact with the original window while the dialog box is open. In this situation, the dialog box remains on top of the browser in a disabled state. If the user navigates away from the original document, the modeless dialog box is automatically dismissed, as all context for the dialog box is lost. An advanced-find functionality might well use such a dialog box to enable the user to select found text in the document while keeping the dialog box open so that he or she can quickly proceed to the next instance of the found text.
Modal dialog box. The modal dialog box allows the program to focus the user's full attention on a particular dialog box and to require interaction with it before continuing. An example of that might be a data-entry operation in which certain data must be entered before the application can continue.

From this link (http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndude/html/dude09252000.asp).

limshady411
08-22-2005, 04:46 PM
Thanks for your response. It's kind of tricky. We have kiosks that we will be setting up that will not be using Internet Explorer, but another browser similar to Firefox. The alert works just fine in Firefox without any issue, except in IE, we have the issue. I'm trying to get either an alert to work on both without issue, or a new popup window with the same message as the alert to work on both. So far, I'm thinking the new window, remaining on focus until the user closes it with a close button, can be the better solution, if I can get it to stay on focus...what do you think? Thanks again!

jscheuer1
08-22-2005, 06:37 PM
Why isn't the alert any good in IE? Alert works nearly identically in IE and FF. In any case, you can keep focus on a popup window until it is closed (at least within the confines of the page that opened it) using this method:

function popUp(URL) {
var page = window.open(URL, 'page2', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 192,top = 144');
page.focus()
document.onclick=function(){
try{
page.focus();return false
}catch(e){}
}
}Another approach would be to use the appropriate modeless or modal dialogue for IE and the alert for FF.

limshady411
08-22-2005, 07:26 PM
Thanks for your response. The alert works fine in IE and FF, however, in IE, it's causing links in my navigation frame to highlight other links (complicated unless you see it). Anywho, the code you gave me does exactly what I need in IE, but in FF, it's not working. If I lose focus, it goes behind my main window, which I don't want, and in the case of the Kiosk, it stays in the background permanently. :confused: any other ideas?? Thanks though, if we went with IE for the Kiosk, we would be set right now...

jscheuer1
08-22-2005, 08:14 PM
In FF there is a configuration option that will allow it to work as in IE.

Tools - Options - Web Features - javascript - advanced

Make sure "Raise or lower windows" is checked. Since you have control over the browsers used in your Kiosks (I would assume), you can probably set this for one copy of the browser and then clone it to all other copies in some way.

limshady411
08-22-2005, 08:39 PM
Thanks for your response. I check the settings and it was already enabled :confused: So with or without that option, it doesn't keep the focus...any other thoughts? Thanks again!

jscheuer1
08-22-2005, 09:28 PM
Odd, worked here. The really promising suggestion I made that you seem to have overlooked is to use one method for IE and another for FF. Generally IE can be selected:


if (document.all){
code for IE goes here
}
else {
code for FF goes here
}It is more complicated than that in the 'real world' but, if you are only using the two browsers, that is sufficient.

limshady411
08-23-2005, 08:10 PM
Thanks. This does exactly what I needed it to do. The kiosk software that I'm using seems not to be Mozilla Firefox because it doesn't do the alert (the else statement if the browser was anything other than IE), but instead, it does a pop up window, which should be IE. I think this kiosk browser is utilizing some component of IE. It's very strange. Thanks for all your help!

jscheuer1
08-24-2005, 05:34 AM
The only other browser aside from IE that utilizes document.all that I know of is Opera. It can be selected out using:

if (document.all&&!window.opera){
code for IE goes here
}
else {
code for Mozilla & Opera goes here
}

glenngv
08-24-2005, 05:44 AM
Firefox also has modal dialogs by specifying modal=1 in the window feature.

var win;
if (window.showModalDialog) { //IE
win = window.showModalDialog("test.htm" , "", "dialogWidth:500px; dialogHeight:500px;");
}
else{
win = window.open("test.htm", "modalWin", "modal=1, width=500, height=500");
}

limshady411
08-24-2005, 05:28 PM
Thanks for your responses. The browser that I'm using seems to integrate IE...it's odd. It's from a company called Arlington (http://www.arlington.com.au/akb/moreinfo.htm). It's odd...

limshady411
08-24-2005, 06:11 PM
I was thinking of another solution...that if my popup does lose focus (which when it does on the kiosk puts its in the background), I can do a timeout to close that window. I just don't know the if statement to do so:

if: <not window.focus()>
timer = setTimeout("window.close()",1000);

What do you think?

Thanks.

glenngv
08-25-2005, 10:59 AM
Have you tried my suggestion?

limshady411
08-25-2005, 07:34 PM
Thanks for your response. Yes, I tried it and I might be able to use it for another piece of the project. However, it's still causing the same issue in IE (as if it were the alert), but it works fine on the kiosk! It's rediculous because the code with if/else with (document.all) works perfectly for IE, perfectly. But on the kiosk, it doesn't like to keep focus. However, with the ModalDialog, the kiosk works perfectly (like the alert does), but it acts up in IE. If I can only get the best of both worlds...It's interesting...thanks. Did we try everything now? :o

jscheuer1
08-25-2005, 11:29 PM
If what you are saying is that you cannot distinguish between the kiosk browser and IE using the document.all test. Try contacting the kiosk browser's maker for a test that will work.

limshady411
08-26-2005, 07:27 PM
Thanks for your response. That would be the ideal thing...they are horrible at emailing me back.

jscheuer1
08-27-2005, 05:20 AM
Some experimentation would be in order then. There is a good chance that this test would yield some useful information, in the body of a test page put this:

<script>
document.write(navigator.userAgent)
</script>Hopefully there will be some difference between what this returns in the kiosk browser from what it returns in IE. If so, unless you know what to do with it, copy the information from each and paste it into a message here. I will then be able to construct a test to branch actions depending upon which browser is in use.

limshady411
08-29-2005, 05:40 PM
Thanks for your response. In IE, I get the following:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)

On the KIOSK, it's identical except it's missing: .NET CLR 1.0.3705;

I hope this missing piece answers our mystery. Please let me know what you discover...

Thanks!

jscheuer1
08-30-2005, 03:00 PM
If that is the case, including this in your code will do it:

if (navigator.userAgent.toLowerCase().indexOf('net clr')==-1) {
kiosk browser specific code goes here
}
else {
IE specific code goes here
}

limshady411
08-30-2005, 05:47 PM
Thanks for your reply. This works fine in Mozilla and Firefox, but for the kiosk browser, it still isn't doing the trick :( For some reason, it's using the else statement and using the IE specific code...not sure...

jscheuer1
08-31-2005, 06:10 AM
Are you sure the differences you reported in your previous post are accurate? Anyways, try this on a test page in both browsers:

<script>
if (navigator.userAgent.toLowerCase().indexOf('net clr')==-1) {
alert('Kiosk Browser')
}
else {
alert('IE Browser')
}
</script>If they both alert as IE, then the kiosk browser has 'net clr' in its navigator.userAgent string after all.

Willy Duitt
08-31-2005, 07:08 AM
Try: alert(document.uniqueID)

limshady411
08-31-2005, 06:13 PM
Thanks for your responses. Ironcially, the alert is what I'm using for this task. Works fine on the kiosk, and IE is ok too, except that it causes an unnecessary issue with a different frame. But, I did what you said, and the alert for both the kiosk and IE say IE. Also, I used the alert(document.uniqueID) and both end up being "ms_id1".

Thanks.

jscheuer1
08-31-2005, 07:49 PM
I'm sorry, I misunderstood your post about the differences. If it was accurate (as my solution was not), this should work:

<script>
if (navigator.userAgent.toLowerCase().indexOf('1.0.3705')==-1) {
alert('Kiosk Browser')
}
else {
alert('IE Browser')
}
</script>

limshady411
08-31-2005, 10:09 PM
Thanks for your response. This works perfectly! This is exactly what I need. Thanks again for your assistance and everyone else who tried. Appreciate it! :thumbsup:

Willy Duitt
08-31-2005, 10:54 PM
Thanks again for your assistance and everyone else who tried. Appreciate it! :thumbsup:

How the heh can we try it?? WE don't have the kiosk browser...
BUT - if document.uniqueID work for both - your kiosk IS IE...

You're making this, by rote of your failure to provide any code or a link - MUCH harder than it ever is/was meant to be...

BTW: If you're using a "kiosk" - what the heh do you care if it works in ANY other browser than the one the "kiosk" supports...

Appears to be circular dumbsh*t to me...
(either that, you're not being truthful - perhaps malicious)

Good Luck;
.....Willy

EDIT: Replace: Good Luck with - Have many nice days!! LOL

limshady411
08-31-2005, 11:01 PM
Thanks for your response. I kind of figured that the kiosk was IE when everything we were trying seems to have the same issue IE was. It's just odd when a piece works in IE and has a different result on the kiosk. I needed both IE and the kiosk to function properly because external users will be using the kiosk. As I said in previous postings, the IE only users are those who are accessing my pages via the Intranet. So it does matter that the code is working on both the kiosk and on plain old IE. This if/else does the trick. Thanks again! :thumbsup:

Willy Duitt
08-31-2005, 11:11 PM
Thanks for your response. I kind of figured that the kiosk was IE when everything we were trying seems to have the same issue IE was. It's just odd when a piece works in IE and has a different result on the kiosk. I needed both IE and the kiosk to function properly because external users will be using the kiosk. As I said in previous postings, the IE only users are those who are accessing my pages via the Intranet. So it does matter that the code is working on both the kiosk and on plain old IE. This if/else does the trick. Thanks again! :thumbsup:

Yeah - the shady in your username tells all...
The 411 tells all as well...

You have not - and am not being honest with us...

Do you even know what a KIOSK is??

.....Willy

limshady411
08-31-2005, 11:29 PM
Thanks for your response. I'm not sure what you are trying to say. :confused: The postings from last week shows the steps we went through trying to resolve my issue, including trying to figure out the browser the kiosk was utilizing. You can download this browser by referring to another posting (I attached the link). Hope this helps. I don't think I was being shady or 411. I said everything from the beginning, and did what you guys asked me to do and test. Thanks for your help.

Willy Duitt
09-01-2005, 12:16 AM
Thanks for your response. I'm not sure what you are trying to say. :confused: The postings from last week shows the steps we went through trying to resolve my issue, including trying to figure out the browser the kiosk was utilizing. You can download this browser by referring to another posting (I attached the link). Hope this helps. I don't think I was being shady or 411. I said everything from the beginning, and did what you guys asked me to do and test. Thanks for your help.

I guess I just don't understand...
To me - a KIOSK is a KIOSK (such as arrival/departure times at an airport or Kmart blue light specials) and there is no need to code cross-browser other than the browser the KIOSK uses... Admins telnet in... What's with all this cross browser stuff?? Please enlighten me...

....Willy

jscheuer1
09-01-2005, 05:12 AM
Willy,

Take a chill pill and read the thread from the start. Honestly, it will all make sense. The kiosk BTW is a stand alone PC installation like you see at computer fairs and such, with a proprietary browser installed to limit access to the content being showcased. It just so happens that this particular kiosk browser tends to identify itself as IE in almost every conventional way we tried yet, behaves differently in certain situations. There is a link to the kiosk browser's manufacturer's site in this thread up there somewhere.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum