1

I have a website that is using two different views, namely desktop and mobile. Generally for blogs hosted on Blogger will display a mobile version of your blog when combined ?m=1 at the end of the blog url.

  My website is quite risky if the user turns using chrome or another browser to the desktop but with an additional open my web ?m=1

Now I ask.

Is it possible to prohibit the user opens the mobile version of my blog when he used the computer / PC / Laptop?

Please explain, thank you

Norax
  • 111
  • 7

1 Answers1

1

We can detect the UserAgent of the browser and if it isn't mobile, then we can replace the query parameter m=1 with m=0 (which redirects to the desktop version)

Adding the following code to the <head> tag of the template should work (The UserAgent condition courtesy of What is the best way to detect a mobile device ) -

<script>
if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && location.search.match("m=1") != null) 
{
location.search = location.search.replace('m=1','m=0')
}
</script>

Note: Make sure that you are using the Custom Mobile template to make this work (In Blogger dashboard > Template tab > Gear Icon > Check Yes. Show mobile template on mobile devices. > Select Custom in Choose mobile template dropdown )

Community
  • 1
  • 1
Prayag Verma
  • 5,500
  • 3
  • 27
  • 53