Close Screen JavaScript

Hey, can anyone tel me the code to close the screen usi9ng javascript, andthen do you know if i can add an alert onto that so before the screen closes it says thanks for visiting, blah blah?