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 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
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

View user profile

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by SLGray 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?


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 : 50441
Reputation : 3478
Language : English
Location : United States

View user profile https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Fildragon 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.
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

View user profile

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

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

Male Posts : 13244
Reputation : 2991
Language : English & 日本語
Location : Pennsylvania

View user profile https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

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

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

View user profile

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Ape 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.


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 Keep_s10
Javascript distinguish mobile from desktop Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 17963
Reputation : 1913
Language : fluent in dork / mumbojumbo & English haha

View user profile http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

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

I did mark it as solved
Fildragon
Fildragon
New Member

Posts : 21
Reputation : 1
Language : english

View user profile

Back to top Go down

Solved Re: Javascript distinguish mobile from desktop

Post by Ape March 22nd 2017, 12:41 am

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 Keep_s10
Javascript distinguish mobile from desktop Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 17963
Reputation : 1913
Language : fluent in dork / mumbojumbo & English haha

View user profile 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