You don't have access to browser functionaloty from script, good thing you have not.
One thing you could do is register a confirm function to the BEFOREUNLOAD event of GI. Then the user gets a confirm dialog whether to leave the page or not, like it is done in the GI IDE.
In your project settings "onLoad Script":
jsx3.gui.Event.subscribe(jsx3.gui.Event.BEFOREUNLOAD, checkExit);
In your code:
function checkExit() {
arguments[0].returnValue = 'your confirm message';
};