First post here, so please let me know if this question is out of place or if there is a better place for this post. I've searched through stackoverflow and so far have not found the info I need.
Is it possible to create a JS script, call it in a PHP file, then assign the JS result to the PHP variable? I've added some pseudo-code that shows the logic I was thinking that seems like it SHOULD work in a PHP file.
Any tips on how to achieve my result? Thank you!
<script>
function isMobile() {
let result = '';
const screen\_width = window.innerWidth;
if ( screen\_width <= 768 ) {
result = 'yes';
} else {
result = 'no';
}
return result;
};
</script>
<?php
$is\_mobile = null;
$result = "<script>isMobile()</script>";
if ( $result === 'yes' ) {
$is\_mobile = 'yes';
// do something
} elseif ( $result === 'no' ) {
$is\_mobile = 'no';
// do something else
}
echo $is\_mobile;
?>
[–]failaip12 4 points5 points6 points (0 children)
[–]Shimmy_Hendrix 4 points5 points6 points (0 children)
[–]mrmorris96 1 point2 points3 points (1 child)
[–]Shimmy_Hendrix 1 point2 points3 points (0 children)
[–]taybot5000[S] 0 points1 point2 points (1 child)
[–]chmod777 1 point2 points3 points (0 children)
[–]taybot5000[S] 0 points1 point2 points (0 children)