You can keep it open, if you launch a permanently running script from your opening page, as a separate process, with built-in webserver, and which handles both the web interface and the SSH connection, for one session.
You can see two versions of this type of script in merlyn's excellent columns, using Chatbot::Eliza as an example of a stateful conversation. You can find them under the title Doctor is IN, see the columns 23 and
24.