I have some problem with page load on desktop browser and mobile browser. In this case I have 4 html page one is home.html
, second is home-mobile.html
, third is product.html
and fourth is product-mobile.html
. My problem is I don't know to switch the html page if opened in mobile browser. For the example is when I open www.example.com in desktop the page will call home.html
but when I open www.example.com in mobile the page will call home-mobile.html
and so with product page, when I open www.example.com/product in desktop it will call product.html
but when I open www.example.com/product in mobile it will call product-mobile.html
. The point is how could I open one link and it will detect opened in desktop browser or mobile browser and call different html page.
Which I have been done now but still not working is :
<script>
window.mobilecheck = function() {
var check = false;
if(window.innerWidth<768){
check=true;
}
return check;
}
if(window.mobilecheck()){
window.location.href="home-mobile.html";
}
else {
window.location.href="home.html";
}
</script>
But with that script the URL was changing and not be the same.
Please anyone know how to do this could help me. Thanks.