When you type JavaScript into a browser address bar it doesn't really interact with the webpage that's already there but with the browser itself.
javascript:this.window.close(); - really does try and close the browser window
javascript:this. window. location. href=" http://microsoft.com "; - does take you to microsoft.com
(remove all the spaces in the above line - Yahoo truncates it when I posted it.
If you try to interact with the webpage it doesn't work so well. If a webpage contains an element with an ID of doorknob then javascript: document.getElementById( 'doorknob') .innerHTML = 'Fred Flinstone'; clears the entire page and "Fred Flintstone" appears on the screen. Again, remove all the spaces to get this to work (or not).
If the webpage does not contain the ID doorknob then you just get an error.
There's a lot of discussion about JavaScript simulating keystrokes - http://www.google.com/search?q=javascript+simulate+keystrokes - luckily it can't do this apart from the page it's on and not to outside the browser. Imagine what would happen if JavaScript could simulate the Ctrl, Alt and Del keys outside the browser!
So to answer your questions...
1) JavaScript from one page can interact with another but only if they are related. parent/daughter/passed by querystring. There was a method of JavaScript cross site scripting (XSS) but that's largely a thing of the past now so no, you can't run your code on Facebook. Besides which it was mostly just malicious links, not actually controlling one site from another.
'
2) As most of these games are written in Flash then no, you aren't going to be able to do that. There are games completely written with JavaScript but you're going to spend a lot of time examining the code and working out how to hook into it,then you have to type the code into the address bar, one line at a time. You may as well just press the keys and play the game properly.