views:

634

answers:

2

Is there a script to make the browser refresh when a page is re-sized? More specifically, one that emulates the browser refresh button or F5? I've found two, but they don't quite do what I'm looking for;

<script type="text/javascript">
var currheight = document.documentElement.clientHeight;
window.onresize = function(){
    if(currheight != document.documentElement.clientHeight) {
        location.replace(location.href);
    }    
}
</script>

and

<body onResize="window.location=window.location;">

The problem with these two is they appear to completely reset the page where as using the browsers refresh function leaves some user made changes intact (like being at a specific hash for instance) which is what I need.

So is there a way to refresh the window on re-size with a script similar to if the browser refresh was clicked? I don't understand why there is even a difference but there is.

Thanks.

+1  A: 

Yes, you probably want to take a look at some JavaScript events. There is an OnResize event.

Here's a link to get you started with events:
http://www.devarticles.com/c/a/JavaScript/OnReset-OnResize-and-Other-JavaScript-Events/

As far as reloading the page, you can do that too:
http://www.mediacollege.com/internet/javascript/page/reload.html

As far as keeping the user values, you could persist them in a session.

Robert Greiner
I'm still pretty new to all this... but the best I can figure out from those links only allows me to do what I've already achieved with the scripts in the OP.Thanks for the input though...
wrsly
A: 

Try this:

<![if !IE]> <body onresize="document.location=window.location;"> <![endif]>
<!--[if IE]> <body onresize="window.location.reload();"> <![endif]-->
Chad