Post Reply

Forums -> Multiple monitors -> JavaScript window.open in proper window
darkbronzemist   2002-12-05 05:39
I have a JavaScript function that calls window.open to give the user a pop-up confirmation dialog before proceeding with an action.

I have my laptop (running Windows XP and IE 6) set up in dual-monitor mode. The LCD is regarded as the primary display; the external monitor, the secondary. The primary display is my left-hand monitor; the secondary, my right-hand monitor.

The problem I'm encountering is this:

If I'm running IE in the left-hand (primary) monitor and I click on the link, the pop-up window appears in the center of the left-hand screen, just as it should. But if I'm running IE in the right-hand monitor and I click on the link, the pop-up window appears in the center of the left-hand monitor! I want it to appear in whatever monitor the main (parent) calling window is located. In this case, the main IE window is in the right-hand monitor. But no matter how I set it up, the pop-up always goes to the primary display.

Here's the code snippet. I pass in the parameters that center the pop-up window on the screen, but I don't know of any way to "force" it to load on a specific monitor.

swidth and sheight are constructed based on the size of the pop-up window and the screen resolution. In my case, I am running 1024x768 on both monitors.

function getRequestView()
{
dbName = "Apps/AdminReq.nsf";
var winWidth = 350;
var winHeight = 60;
var swidth = ( screen.width - winWidth ) / 2;
var sheight = ( screen.height - winHeight ) / 2;
popupWin = window.open( "/" + dbName + "/RequestViewDialog_D?OpenForm","RVWindow","width="+winWidth+",height="+winHeight+",top="+sheight+",left="+swidth );
}

Thanks in advance,
Matt
Nino   2004-04-24 08:43
i too am having the same problem regarding JAVA opening a window
Barton   2004-04-27 00:20
Matt,

I forwarded your question to a friend of mine who writes javascript like you and I write a letter. He's very good.

He sent me this script and it seems to work great no matter what monitor you open the windown on.



Let me know if this helps.

Barton
Barton   2004-04-27 00:20
Oops...forgot to take out the script and /script:


var x = 0, y = 0;

if (document.all) {
y = window.screenTop;
x = window.screenLeft;
}
else if (document.layers) {
x = window.screenX;
y = window.screenY;
}
alert( x + " - " + y);
var popup = window.open('somefile.html','popup','width=100,height=100,top='+y+',screenY='+y+',left='+x+',screenX='+x);
Forums -> Multiple monitors -> JavaScript window.open in proper window

Post Reply