This question already has an answer here:
- What is the difference between client-side and server-side programming? 5 answers
I’m trying to get the browser’s width and then compare it as a php variable, but it is saving it as a string, I tried parsing it to another variable but it only returns 0.
$tam='var j= $(window).width(); document.write(j)';
I’m doing the parsing like this:
<?php echo 'var jVar = "$phpVar";'; ?>
If you are importing your script from a js file you will want to add this before your import or course.
And I’m not sure what you’re trying to accomplish but if you need a js value you can always send that value using an ajax Request…
var ajax = new XMLHttpRequest(); var form = new FormData(); form.append('win_size',window.innerWidth); ajax.open("http://example.com/processJSWindowSize.php","POST",true); ajax.send(form);
On the server side code, which in this example is processJSWindowSize.php, you can have something along the lines of