How can I detect if a web app is opened by a mobile browser or an PC?

Hi all
is that posable to know if a web app is opened by a mobile browser or an PC ?

i just want to post a message on the label if a web app is opened by a mobile browser

i tried to get the Column Width and if the ( Width < 412 ) but its post the message on PC also


1 Like

You can do that by JavaScript easily

1 Like

thank you muneer

i have search on google and i found this JavaScript code but i dont know how to put it on thunkable

can you tell me how please

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
  // true for mobile device
  document.write("mobile device");
  // false for not mobile device
  document.write("not mobile device");
1 Like

Put it in an html file and add this file to project assets you can call it from web viewer component.


like this ??
Screen Shot 2021-03-16 at 1.15.45 PM

1 Like

Yes but if you want to pass the information to your app then you need to integrate the web-viewer extension with the code

1 Like

thank you muneer its working good

i create the html file and test it on my app and its working good
and its test if it the phone or pc and then its post a message to my app

but the last question please how i can get the respond from the test

1 Like

You need to change the code. I’m not in front of my computer now, I can do it for you later if you are confused how to do it.

1 Like

that will be amazing thank you so much
i will wait your replay
thank u

1 Like

The required change is:
document.write(“mobile device”);
ThunkableWebviewerExtension.postMessage(‘mobile device’);

Do the same for the other statement.

Also move the <script scr="https…

Above your code.

1 Like

thank you so so much its working good
have a nice day

1 Like

Same to you @bader_mouti

1 Like