tpeck
03-14-2004, 04:19 AM
Hi. I am trying to tidy up a block of code:
As you can see below, I am invoking another instance of the function NewWindow each time. This is because SpeedText keeps changing. But there must be a more elegant way of doing this with the NewWindow function at the top and a variable called SpeedText.
Trouble is, I've tried many things and failed. Can anyone set up the variable for me so I can study how you did it?
When you call function Flash1a, function Flash2a etc., the code flashes up a popup which is built from the html code in SpeedText. It works (at least on a local machine but not yet from a website), but looks horrible.
Many thanks,
Terry
<!-- Begin
function Flash1a(){
var speedText='<html><head><title>Flashcards - Speed 1</title><script src="flasha/flasher1a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
function Flash2a(){
var speedText='<html><head><title>Flashcards - Speed 2</title><script src="flasha/flasher2a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
function Flash3a(){
var speedText='<html><head><title>Flashcards - Speed 3</title><script src="flasha/flasher3a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
etc. etc.
As you can see below, I am invoking another instance of the function NewWindow each time. This is because SpeedText keeps changing. But there must be a more elegant way of doing this with the NewWindow function at the top and a variable called SpeedText.
Trouble is, I've tried many things and failed. Can anyone set up the variable for me so I can study how you did it?
When you call function Flash1a, function Flash2a etc., the code flashes up a popup which is built from the html code in SpeedText. It works (at least on a local machine but not yet from a website), but looks horrible.
Many thanks,
Terry
<!-- Begin
function Flash1a(){
var speedText='<html><head><title>Flashcards - Speed 1</title><script src="flasha/flasher1a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
function Flash2a(){
var speedText='<html><head><title>Flashcards - Speed 2</title><script src="flasha/flasher2a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
function Flash3a(){
var speedText='<html><head><title>Flashcards - Speed 3</title><script src="flasha/flasher3a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr>';
function NewWindow(mypage,myname,w,h){
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=n o,toolbar=no,directories=no,location=no,resizable=no,status=no';
win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win.focus){win.focus();}
}
NewWindow('popup.html','flashcards','620','140');
}
etc. etc.