Jump to content

Recommended Posts

Hi,

 

I am trying to make a page where the footer is loaded according to the screen size, so if someone is accessing the website via a tablet will be a footer, if it is from the computer, there will be another footer.

 

my problem is that although it is recognizing the windows width, it is not changing the footer accordingly.

 

this is my code:

$width = "<script>document.write(window.innerWidth);</script>";
if ($width < 900)
{
include("footer_mobile.php");
}
else
{
include("footer.php");
}

for some reason it is always loading the else footer even though the windows with changes.

I added echo"$width" ; and the result of the variable was fine.

 

 

does anyone know what the problem is cause it is driving me crazy?

 

Link to comment
https://forums.phpfreaks.com/topic/290794-load-php-page-according-to-screen-size/
Share on other sites

PHP is not the solution. Look at using CSS media quries to display different parts of your web page depending on the device being used.

 

This technique is called Responsive Web Design goggling that term will yeild may articles/tutorials. Such as this page was found

Edited by Ch0cu3r

The only way would be to request the footer using AJAX after you get the width using JS. The php code on the server knows nothing about your javascript, which runs in the browser, AFTER php has stopped processing and sent the data to the browser.

How are you testing to see if the media query(ies) work? Are you adjusting a browser window...or are you testing on a mobile device? If you're testing on a mobile device and it's an iPhone, you'll need to add a <meta> tag to get things working. Perhaps the following article will help:

http://www.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/

 

If you scroll down a bit, there is a section for "Testing in an iPhone" which talks about the <meta> tag.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.