Detecting mobile browser

This is the right place to report general bugs, make suggestions or ask for help.
Post Reply
Lubomír Ludvík
Posts: 63
Joined: Wed Feb 20, 2019 7:44 pm
Location: Rouchovany
Contact:

Detecting mobile browser

Post by Lubomír Ludvík » Sun Jan 05, 2025 6:44 pm

Web looked bad on a mobile device, so I detecting mobile browser and reducing the image preview.

Code: Select all

<script>
if(/Android&#124;webOS&#124;iPhone&#124;iPad&#124;iPod&#124;BlackBerry&#124;IEMobile&#124;Opera Mini/i.test(navigator.userAgent)){
  document.currentScript.outerHTML = `[img=images/mapka_apartmany.jpeg scale=5% float=right]`;
}else{
  document.currentScript.outerHTML = `[img=images/mapka_apartmany.jpeg scale=18% float=right]`;
}
</script>
Is extension that detects the mobile and change the template or change .css?

Lubomír Ludvík
Posts: 63
Joined: Wed Feb 20, 2019 7:44 pm
Location: Rouchovany
Contact:

Re: Detecting mobile browser

Post by Lubomír Ludvík » Mon Jan 06, 2025 2:30 am

and I change css style:

Code: Select all

@media only screen and (max-width: 480px) { ... }

User avatar
fraenkiman
Posts: 282
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: Detecting mobile browser

Post by fraenkiman » Thu Jan 09, 2025 11:14 pm

Hello Lubomír,

try the mobile plugin. The code may need to be updated.

Have a good weekend
With best regards
Frank
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

User avatar
Arvid
FlatPress Coder
Posts: 603
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Detecting mobile browser

Post by Arvid » Sun Jan 12, 2025 12:59 pm

Ahoj Lubomír,

šťastný nový rok! :D

The Mobile plugin works fine, I use it on my personal website.
But it's basically a workaround; the best way to serve a good layout to big and small screens is proper use of responsive web design.
Check out https://flatpress.org for example :)

All the best,
Arvid

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest