I'd like to auto refresh/reload webpage when user tilts his iPad. I've done alot of reseach but am not able to find a solution. Before wasting another day searching for answers, does anyone know if this is this even possible?
Asked
Active
Viewed 9,832 times
1
-
use window.onorientationchange function to get this – Dineshkani Dec 05 '12 at 10:37
3 Answers
8
window.onorientationchange = function()
{
window.location.reload();
}

VMAtm
- 27,943
- 17
- 79
- 125

Dineshkani
- 2,899
- 7
- 31
- 43
-
-
-
@ThomasBLund Actually, remember the semi-colon at the end of the last closing brace. – crmpicco Jun 14 '13 at 10:17
-
This is unnecessarily slow, because it will reload the entire page, including images and everything. See [this answer](http://stackoverflow.com/questions/7919172/what-is-the-best-method-of-re-rendering-a-web-page-on-orientation-change/31357325#31357325) for a much faster solution (10 miliseconds). – Dan Dascalescu Jul 11 '15 at 12:58
0
Note: this question is a duplicate and should be closed. I'll post the gist of my answer here.
window.addEventListener('orientationchange', function () {
var originalBodyStyle = getComputedStyle(document.body).getPropertyValue('display');
document.body.style.display='none';
setTimeout(function () {
document.body.style.display = originalBodyStyle;
}, 10);
});
The code listens to the orientationchange event and forced a re-flow of the body
element by hiding it and showing it 10 milliseconds later. It does not depend on any <meta>
tags or media queries. And it doesn't reload the entire page.

Community
- 1
- 1

Dan Dascalescu
- 143,271
- 52
- 317
- 404
-1
You can call the delegate of UIWebview on orientation change like this
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[_webview reload];
}
You also need to include UIWebviewDelegate in .h file and assign delegate to self.

ask4asif
- 676
- 4
- 10