It's pretty simple, but not straight forward, I will give you some hints since I know how it can work but I dont have any testing code done:

You will need to use AJAX here, the idea is to call a php file onload using js, this php file will set the session, and in the main page you will check if this session is set or not.

This snippet here can give you some idea:
http://www.webtoolkit.info/ajax-file-upload.html

Please note that in this snippet the upload.php file in called when the form is submitted, in your case you will want to call the file when the page is loaded, so you will init it in body onload.

Now in your php file, assuming you put it in store root dir:
1. you have to include application top first to init session
require_once('includes/application_top.php');
2. The set the session
$_SESSION['js_on'] = true;

And that's it.