The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Javascript distinguish mobile from desktop

View previous topic View next topic Go down

Solved Javascript distinguish mobile from desktop

Post by Fildragon on March 20th 2017, 7:37 pm

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 March 21st 2017, 9:07 pm; edited 1 time in total
avatar
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by SLGray on March 20th 2017, 8:45 pm

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?


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

avatar
SLGray
Administrator
Administrator

Male Posts : 38231
Reputation : 2576
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon on March 20th 2017, 9:21 pm

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.
avatar
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 on March 21st 2017, 1:35 am

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');
  }
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13083
Reputation : 2758
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon on March 21st 2017, 7:32 am

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

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by APE on March 21st 2017, 2:40 pm

@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.



avatar
APE
Manager
Manager

Male Posts : 9683
Reputation : 882
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

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

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon on March 21st 2017, 9:07 pm

I did mark it as solved
avatar
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by APE on March 22nd 2017, 12:41 am

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



avatar
APE
Manager
Manager

Male Posts : 9683
Reputation : 882
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

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

Back to top Go down

View previous topic View next topic Back to top


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