Easiest (and I think only) way, is to store the content into a variable before you remove it:
$(window).on('load',function() {
var body;
var bodyVisible = true;
function resize() {
if (bodyVisible==true && $(window).innerHeight()<450) {
bodyVisible = false;
body = $('body').html(); //store current body content before removing it
$('body').html("Please resize your screen.");
} else if (bodyVisible==false && $(window).innerHeight()>=450) {
bodyVisible = true;
$('body').html(body); //restore body content
}
}
resize(); //invoke resize() on page-load
$(window).resize(resize); //invoke resize() on page-resize
});
fiddle: http://jsfiddle.net/zyL6fyvn/3/
- See comments in the code above for explanation.
- I put the resize code inside a standard function that is invoked once on page-load and after that on every page-resize. (Otherwise the content will still show if the window's height is below
450
, until you have resized once.)
- I added the
bodyVisible
boolean, otherwise the body content is rewritten again on every resize. Now it's only rewritten once when the height passes the threshold.
- I prefer to use
.innerHeight()
instead of just .height()
, I get more consistent and reliable results with that. But that's just my opinion.
- In your HTML, try to close your
<input />
and your <br />
elements (the space before the slash is no typo).
(I have never seen a <br />
with a class btw, or CSS being applied to it for that matter.. but apparently it works, and it's even officially valid:)