Click to See Complete Forum and Search --> : Flash with popupwindow JavaScript


guitz
05-27-2003, 02:26 AM
Hello...

I have a JavaScript code wich allows me to open a centered popup window:

<script language="JavaScript"><!--

//openPopup
function openPopup(width,height) {
x = (640 - width)/2, y = (480 - height)/2;

if (screen) {
y = (screen.availHeight - height)/2;
x = (screen.availWidth - width)/2;
}
if (screen.availWidth > 1800) {
x = ((screen.availWidth/2) - width)/2;
}
window.open('http://www.myURL.com','myURL','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left ='+x);
}

//--></script>

I call this script with Flash using this ActionScript method :

getURL ("JavaScript:openPopup(750,450)");

It's pretty usefull if you have one URL to display in your popup, but when I have 10 differents popups with differents URLs, I duplicate 10 times this code in my HTML document, changing the name and the URL, and the result is an heavy HTML document...

So my problem is...

Is there a way to customize this JavaScript :function openPopup(width,height) with the URL too??

For example : function openPopup(URL,width,height)

in order to call it with Flash, with this ActionScript method:

getURL ("JavaScript:openPopup(http://www.myURL.com,750,450)");

Thank you for helping me... :confused:

Gollum
05-27-2003, 02:47 AM
How 'bout this...

<script language="JavaScript"><!--

//openPopup
function openPopup(url, width,height)
{
x = (640 - width)/2, y = (480 - height)/2;

if (screen)
{
y = (screen.availHeight - height)/2;
x = (screen.availWidth - width)/2;
}
if (screen.availWidth > 1800)
{
x = ((screen.availWidth/2) - width)/2;
}
window.open(url,'myURL','width='+width+',height='+height+',sc
reenX='+x+',screenY='+y+',top='+y+',left='+x);
}

//--></script>


then I guess you would call it like this...

getURL ("JavaScript: openPopup('http://www.myURL.com',750,450)");

note the use of single quotes within the double quotes so that javascript recognises the first argument as a string.

or, if single quotes won't do, embed double quots alla VB style
getURL ("JavaScript: openPopup(""http://www.myURL.com"",750,450)");

guitz
05-27-2003, 03:17 AM
:D :D :D

Thank you Gollum it works!!!!

You have saved 4 kb in my Html document with this trick!!!

It was so easy for you!!!

thank U again

guitz