Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to do something that goes far over my current skills yet I believe I can do it, I would be imensely thankfull if you point me to an already developed script for this matter.

My question comes from what runs first? Javascript or php? because I need to asynchronosly include a php file into the page.

My idea is this, if user has a screen width wider then 1024, draw an extra fixed position div, if not, don't draw it. That div is supposed to take in a flash object with a clickable link.

My idea would be to:

  1. Get resolution with javascript.
  2. Use jQuery to send ajax json var into .php file that stores res vars into a session cookie.
  3. Read the cookie with php, decide to include the extra .php file or not. That file should then eco the extra div with flash object.

Is this possible? Is there an easier way? Since this is to include in a Zencart personal store of mine, does it conflicts with the zencart cookie session or can a user have more then 1 type of session cookie per website? it can right?

Best Regards, any help appreciated, Joricam

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

Yes, it's possible - but now in the way you're describing. PHP runs server side and Javascript runs client side, i.e. PHP is executed before any Javascripts. However, nothing says you cannot do this only with Javascript - and it would actually be trivial to solve with jQuery (as you tagged the question with it). Just let your Ajax called PHP-page return the inline HTML, and print it with jQuery instead. No need for cookies, either.

share|improve this answer
add comment

PHP runs first because the page hasn't loaded yet and javascript is run user-side, but once the page is loaded, ajax allows you to make calls to a php script and recieve a result that you can then add to the page via javascript.... so yes it's doable:)

Sessions can contain as many keys as you need them to, just name them something specific

share|improve this answer
1  
Yes, I'm an idiot, this is even easier, I can just user javascript/jquery to load the external html into a div if the screen res is higher then 1024, I don't even need php, just jquery and ajax! ... shame on me. –  Ricardo Mustra Jun 15 '11 at 23:07
add comment
<script language="javascript">
if (window.location.search == "") {
    window.location.href = window.location + "?width=" + screen.width + "&height=" + screen.height;
} 
</script>

This will redirect the page you try to access to the same page but sending parameters to the page.

Then you would be able to:

<?php
$width = $_get['width'];
$height = $_get['height'];
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.