The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Javascript distinguish mobile from desktop

4 posters

Go down

Solved Javascript distinguish mobile from desktop

Post by Fildragon Mon Mar 20 2017, 18:37

Is there a way within forumotion to distinguish if the user is running the mobile or desktop version or would I have to use the useragent in javascript. I want my script to only run on the desktop version as it breaks the mobile version if it executes there.


Last edited by Fildragon on Tue Mar 21 2017, 20:07; edited 1 time in total
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by SLGray Mon Mar 20 2017, 19:45

So you want this JavaScript to not run while someone is viewing your forum in mobile version?  Does it work fine when you switch to classic version?


Javascript distinguish mobile from desktop Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51463
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon Mon Mar 20 2017, 20:21

www.igdid.com

yes, it works fine on the forum (though I have disabled it for now). But if the javascript loads on the mobile version it causes issues there. So I would like to adjust my js so that if the mobile version loads it doesnt load this script.
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Ange Tuteur Tue Mar 21 2017, 00:35

Hey,

You can check the _userdata object to see if tpl_mobile has been defined. For example :
Code:
$(function() {
  if (!_userdata.tpl_mobile) {
    console.log('Desktop');
  }
});

Remove the NOT flag "!" if you want the if block to run code for mobile instead. You can also do the standard if ... else statement.
Code:
$(function() {
  if (_userdata.tpl_mobile) {
    console.log('Mobile');
  } else {
    console.log('Desktop');
  }
});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon Tue Mar 21 2017, 06:32

Thankyou so much, you have just my job so much easier. This works great Smile
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Ape Tue Mar 21 2017, 13:40

@Fildragon is this now solved ?

If yes then please follow the rules and click the green mark solved button on the first post this will then mark the thread solved and a staff member can close it and more it to the right place.

A big thank you to @Ange Tuteur for he's help in this topic.


Javascript distinguish mobile from desktop Left1212Javascript distinguish mobile from desktop Center11Javascript distinguish mobile from desktop Right112
Javascript distinguish mobile from desktop Ape_b110
Javascript distinguish mobile from desktop Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19084
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon Tue Mar 21 2017, 20:07

I did mark it as solved
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Ape Tue Mar 21 2017, 23:41

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


Javascript distinguish mobile from desktop Left1212Javascript distinguish mobile from desktop Center11Javascript distinguish mobile from desktop Right112
Javascript distinguish mobile from desktop Ape_b110
Javascript distinguish mobile from desktop Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19084
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum