window.onbeforeunload not working in chrome

It seems that the only thing you can do with onbeforeunload in recent version of Chrome is to set the warning message.

window.onbeforeunload = function () {
    return "Are you sure";
};

Will work. Other code in the function seems to be ignored by Chrome


UPDATE: As of Chrome V51, the returned string will be ignored and a default message shown instead.

Leave a Comment