2022-06-28, 08:03 PM
Hello and thank you in advance for the help.
I am wanting to be able to detect screen size (perhaps with javascript screen.width <= 800 for example) and I want to be able to have it use a different theme based upon this.
A few things:
1) I am not opposed to running a separate installation for example one mybb in root / and one in /mobile if that is something that can easily be done.
2) PLEASE do not suggest ways of "using mobile themes." Respectfully I have searched and searched and we simply cannot find a theme that fits both the desktop and mobile/responsive needs. Separate themes are a must.
3) It is also possible for a user to be using a laptop, then jump on their phone, then back to laptop for example so this solution needs to work easily flipping based upon screen size.
I have tried this in the header:
I then modified global.php as:
That bypassed the verify_post_check which likely wasn't smart but I was working on a concept to build on.
The above solution kind of works, except users cannot then navigate the site without a redirection each time it loads, and a check is needed on every page (could come from bookmark etc)
So what I am needing to do is basically:
Any time that any page loads, check if the screen size is > 800 (800 not important, just a number for now) and based upon that set the theme for that page load. Can anyone help me and tell me how to do this?
It would also be nice not to rely on javascript as some people disable it, but that is only a bonus.
I am wanting to be able to detect screen size (perhaps with javascript screen.width <= 800 for example) and I want to be able to have it use a different theme based upon this.
A few things:
1) I am not opposed to running a separate installation for example one mybb in root / and one in /mobile if that is something that can easily be done.
2) PLEASE do not suggest ways of "using mobile themes." Respectfully I have searched and searched and we simply cannot find a theme that fits both the desktop and mobile/responsive needs. Separate themes are a must.
3) It is also possible for a user to be using a laptop, then jump on their phone, then back to laptop for example so this solution needs to work easily flipping based upon screen size.
I have tried this in the header:
<script type="text/javascript">
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
<!--
if (screen.width <= 800 && urlParams.get('theme') != 3) {
window.location = "https://example.com/?theme=3";
} else if(screen.width > 800 && urlParams.get('theme') != 7) {
window.location = "https://example/com/?theme=7";
}
//-->
</script>
I then modified global.php as:
//if(isset($mybb->input['theme']) && verify_post_check($mybb->get_input('my_post_key'), true))
if(isset($mybb->input['theme'])) {
if($mybb->input['theme'] == '3' || $mybb->input['theme'] == '7') {
That bypassed the verify_post_check which likely wasn't smart but I was working on a concept to build on.
The above solution kind of works, except users cannot then navigate the site without a redirection each time it loads, and a check is needed on every page (could come from bookmark etc)
So what I am needing to do is basically:
Any time that any page loads, check if the screen size is > 800 (800 not important, just a number for now) and based upon that set the theme for that page load. Can anyone help me and tell me how to do this?
It would also be nice not to rely on javascript as some people disable it, but that is only a bonus.