Are you running that JS overwrite as the last thing before closing the 
page? If you do it but then refresh the page, your changes will be lost. 
You'd need to make it the penultimate command:

br.goto "http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm"
br.execute_script("window.onbeforeunload = null")
br.close rescue nil

The above works for me, does it work for you? If that isn't working then 
can you post the JavaScript code from the page, and the code you're 
using which isn't working? It might be a variant on that function, like 
"window.onunload" that you need to overwrite.

-- 
Posted via http://www.ruby-forum.com/.