Q:

Javascript window.onresize doesn't seem to provide more than one update?

How can I get window.onresize to follow the user's multiple window resizes? I have the following Javascript code that prints out the window size. It only provides one update:
var someStuff = ['<p id="page"></p>'];
document.write(someStuff);
var widthWin = $(window).width();
document.write('<p>'+widthWin+'</p>');

window.onresize = function() {
    var element = document.getElementById("page");
    element.parentNode.removeChild(element);
    document.write(someStuff);
    widthWin = $(window).width();
    //widthWin = window.innerWidth;  //I tried this too
    document.write('<p>'+widthWin+'</p>');
}

Or perhaps I'm approaching this completely the wrong way?

A:

The code document.write('<p>'+widthWin+'</p>'); replace the content of the html, it means that the window.onresize function is also removed.
If you want to replace the content of the page, you can do something like: document.body.innerHTML = ""
Anyway here is a code example removing this document.write, to test it just resize the window and you can see that it shows the new size:
 <body>
    this is my page test<br/>
    size: <span id="page"></span>

    <script>

    showWindowSize();

    window.onresize = function() {    
        showWindowSize();//show window size everytime window change          
    }

    function showWindowSize(){
        var element = document.getElementById("page");
        //get width size of the body
        var widthWin = window.document.body.clientWidth;
        page.innerHTML=widthWin;
    }
    </script>
</body>

