unfortunately, there's no way to do what you want with PHP.
PHP runs on the server.
You want the client to do something, without asking the server for the page again.
Javascript is client side, and if you embed an applet, that might work also.
You need code that will execute on the client's machine.
This may sound wierd, and it's probably not the best way, but you could create a listener in PHP and have javascript that serves as a client to the listener. However, the code for this can be complex.