I am trying to direct mobile users automatically into a different HTML if they are mobile users.
I know how to figure out their platform name , but I do not know the platform names which are mobile. and I do not know how to make it so that if there is a specific result , to automatically open a different HTML for the user in the same tab that the user is in.
I would very much appreciate if any one who knows how to do so could help.
CodePudding user response:
Try this in the page header:
var mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
if( mobile.test(navigator.userAgent) ) {
document.location = 'm.example.com'
}
CodePudding user response:
Deciding what does and doesn't require a mobile interface is up to you. In my case changing to mobile interface when screen width is below 750px works best.
if ( parseInt(screen.width) <= 750 ) {
window.location.href = "https://myurl";
}
Using window.location.replace("https://myurl"); will replace the current window (can't go back).
