Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: neat and tidy

  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts

    neat and tidy

    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="javascriptarent.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="javascriptarent.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="javascriptarent.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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •