...

View Full Version : neat and tidy



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.

glenngv
03-14-2004, 09:34 AM
function NewWindow(mypage,myname,w,h, num){

var speedText='<html><head><title>Flashcards - Speed '+num+'</title><script src="flasha/flasher'+num+'a(AC).js" language="JavaScript1.2"></script></head><body onLoad="self.focus()" onBlur="self.focus()"><a href="javascript&#58;if (opener&&!opener.closed)opener.focus();window.close()"><p align="right"><font face="Arial" color="#808080" size="1"><i>Close Window</i></font></p></a><hr>';

var LeftPosition=(screen.width)?(screen.width-w)/2:100;
var TopPosition=(screen.height)?(screen.height-h)/2:100;
var settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPositon+',scrollbars=no,menubar=no ,toolbar=no,directories=no,location=no,resizable=no,status=no';
var win=window.open(mypage,myname,settings);
win.document.write(speedText);
win.document.close();
if(win && !win.closed) win.focus();
}

NewWindow('popup1.html','flashcards1','620','140',1);
NewWindow('popup2.html','flashcards2','620','140',2);
NewWindow('popup3.html','flashcards3','620','140',3);
...

If you want it neatier and better, don't use <font> tags and use CSS to put style in your document.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum