0

I got screen width by using javascript:-

<script type="text/javascript">var sw = document.body.scrollWidth ;</script>

Then i stored the value of the width in a php variable :-

$screenWidth1 = "<script>document.writeln(sw);</script>";

Now i want to use $screenWidth1 in a condition like this:-

if ($screenWidth1 < '960') {echo "working";} 

But it does not work, when we print $screenWidth1, it shows the correct value, but in condition its not work.

Please let me know if there any solution.

Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
  • 2
    You can't set PHP variables from Javascript. PHP runs when the page is being sent to the client, Javascript runs after it's done. – Barmar May 26 '15 at 06:31
  • 1
    `document.write` happens on the client, not the server. – Barmar May 26 '15 at 06:32

0 Answers0