Skip to main content
June 2, 2009
Answered

centering a pop-up browser window

  • June 2, 2009
  • 1 reply
  • 1873 views

Does anyone know how to horizontally and vertically center a browser pop-up window in Flash?


Below is the code tied to my Flash button:


on (release) {
    getURL("javascript:openNewWindow('http://www.blahblahblah.com','thewin','height=300,width=400,toolbar=no,location=no,menubar=no,status=no,scrollbars=yes') ");
}

And here's the code on my HTML page:

<SCRIPT LANGUAGE=JavaScript>
function openNewWindow(URLtoOpen, windowName, windowFeatures) {
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

</SCRIPT>

<A HREF=javascript:openNewWindow('http://www.blahblahblah.com','thewin','height=300,width=400,toolbar=no,location=no,menubar=no,status=no,scrollbars=yes') ></A>

Any suggestions would very very helpful!

Thank you,

Nicole

This topic has been closed for replies.
Correct answer kglad

oops, you need to pass or hardcode the width (w) and height (h) of your window to your openNewWindow() function.  and after testing i see some typos.  use:

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
   
    var winl = (screen.width-400)/2;
    var wint = (screen.height-300)/2;

    windowFeatures = 'top='+wint+',left='+winl+','+windowFeatures;
    newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}

</script>


no, recheck my message #3.  i corrected some typos.  in particular, the highlighted line below is different from my first reply.


function openNewWindow(URLtoOpen, windowName, windowFeatures) {
   
    var winl = (screen.width-400)/2;
    var wint = (screen.height-300)/2;

    windowFeatures = 'top='+wint+',left='+winl+','+windowFeatures;
    newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}

</script>

1 reply

kglad
Community Expert
Community Expert
June 2, 2009

function openNewWindow(URLtoOpen, windowName, windowFeatures) {

var winl = (screen.width-w)/2;

var wint = (screen.height-h)/2;

windowFeatures = 'top='+wint+'left='+winl+windowFeatures;

newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}

// end script here -->

</script>

June 2, 2009

Thank you so much!  For some reason the pop up won't appear now after clicking on the button though.  There's no error message or anything.... just nothing happens.

Just to make sure, I'm replacing this code:

<SCRIPT LANGUAGE=JavaScript>
function openNewWindow(URLtoOpen, windowName, windowFeatures) {
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

</SCRIPT>

with this code, right?

<SCRIPT LANGUAGE=JavaScript>

function openNewWindow(URLtoOpen, windowName, windowFeatures) {

var winl = (screen.width-w)/2;

var wint = (screen.height-h)/2;

windowFeatures = 'top='+wint+'left='+winl+windowFeatures;

newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}

</script>

kglad
Community Expert
Community Expert
June 3, 2009

oops, you need to pass or hardcode the width (w) and height (h) of your window to your openNewWindow() function.  and after testing i see some typos.  use:

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
   
    var winl = (screen.width-400)/2;
    var wint = (screen.height-300)/2;

    windowFeatures = 'top='+wint+',left='+winl+','+windowFeatures;
    newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}

</script>