JS onload和onbeforeunload

<script type="text/javascript">
window.onload = function() {
    alert('页面加载完毕喽!!!!');
    //获取元素
    var test = document.getElementById('test');
    test.onclick = function(){
        alert('this is a div');
        test.style.border = 'dashed 5px red';
    }
}

window.onbeforeunload = function() {
    return '您确定要离开页面么??'; //这里不能使用alert
}

</script>
<div id="test" style="width:200px;height:200px;background:#112311"></div>