Javascript distinguish mobile from desktop
4 posters
Page 1 of 1
Javascript distinguish mobile from desktop
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- New Member
- Posts : 21
Reputation : 1
Language : english
Re: Javascript distinguish mobile from desktop
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?
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: Javascript distinguish mobile from desktop
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.
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- New Member
- Posts : 21
Reputation : 1
Language : english
Re: Javascript distinguish mobile from desktop
Hey,
You can check the _userdata object to see if tpl_mobile has been defined. For example :
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.
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');
}
});
Re: Javascript distinguish mobile from desktop
Thankyou so much, you have just my job so much easier. This works great
Fildragon- New Member
- Posts : 21
Reputation : 1
Language : english
Re: Javascript distinguish mobile from desktop
@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.
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.
Re: Javascript distinguish mobile from desktop
I did mark it as solved
Fildragon- New Member
- Posts : 21
Reputation : 1
Language : english
Re: Javascript distinguish mobile from desktop
Problem solved & topic archived.
|
Similar topics
» how to force Desktop on mobile
» return from desktop to mobile version
» Desktop-only CSS
» How To Force Your Desktop Version Theme "Colors And Banner" To Be Used In The Mobile Version?
» Difference between the desktop view and the mobile view of layout
» return from desktop to mobile version
» Desktop-only CSS
» How To Force Your Desktop Version Theme "Colors And Banner" To Be Used In The Mobile Version?
» Difference between the desktop view and the mobile view of layout
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum