Reputation: 131
I'm trying to make a page that when resize window less than 767, than refresh page one time.
So I searched lot of examples, and this is my code below
$(document).ready(function(){
$(window).on('resize',function(){
if ($(window).width() < 767) {
location.reload(); // refresh page
}
else {
// width more than 768px for PC
}
});
});
The problem is that code works fine on PC browser. But, on the mobile browser, it keeps refreshing and refreshing infinitely...
What do I need to fix the code to not refresh page when its mobile ?
Only refresh when window size less than 767px on PC ?
Upvotes: 0
Views: 289
Reputation: 2192
<script>
$(document).ready(function()
{
$width = $('#content').width();
$('#content img').css(
{
'max-width': $width, 'height': 'auto'
});
});
</script>
Upvotes: 0
Reputation: 5356
You can make session cookie for that
$(document).ready(function(){
$(window).on('resize',function(){
if ($(window).width() < 767 && !document.cookie.match('refresh')) {
document.cookie = "refresh=1; expires=0; path=/"
location.reload(); // refresh page
}
else {
// width more than 768px for PC
}
});
});
check refresh cookie is not exists then refresh the page
Upvotes: 1
Reputation: 1630
What you can do is set a session in php to remember if the user have done a resize
Upvotes: 0