Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:30:13+00:00 2026-06-01T00:30:13+00:00

I am currently using jQuery to load a variable php layout depending on the

  • 0

I am currently using jQuery to load a variable php layout depending on the browser width.

function setLocation(url) {
   if (window.location.href.indexOf(url) === -1)
      window.location = url;
}

function reloadPage(width) {
    width = parseInt(width);
    if (width < 701) {
        setLocation("layout700.php");
    } else if (width < 900) {
        setLocation("layout900.php");
    } else {
        setLocation("layout1200.php");
    }
}

$(function() {
   reloadPage($(this).width());
   $(window).resize(function() {
       reloadPage($(this).width());
   });
});

My Questions :

Q1. Is it possible to accomplish this with just php? If yes, how?

Q2. Can I do this using PLAIN JAVASCRIPT (No jQuery, MooTools or other libraries) If yes, how?

I dont want to use those libraries because this is the only javascript function in my template and currently just to do this I am loading the entire jQuery library. Please help.

Why do I want to do this when I can simply re-arrange my layout with CSS?

I do not want to use the CSS property #div { display:none } as the issue is that my layouts are loaded with very many images and widgets.

I even tried a responsive layout but unfortunately some of the image details are hardly visible in small screens.

Using css property display:none, will still loads the un-displayed content wasting a lot of bandwidth. Lets say for a mobile browser to load 1.5 MB of site and then hide 1.2 MB of it???? Well that may not be a good idea.

For smaller browsers these widgets will not make any sense, hence I would want to load a lighter version of the same.

This is what I think. Please feel free to correct me if I am wrong as I am still a novice when it comes to programming and am still in the learning stage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:30:15+00:00Added an answer on June 1, 2026 at 12:30 am

    Q1. Is it possible to accomplish this with just php? If yes, how?

    To a certain extent, you can identify mobile devices. However, a user’s screen resolution is not available in PHP.

    Q2. Can I do this using PLAIN JAVASCRIPT (No jQuery, MooTools or other libraries) If yes, how?

    Yes. In fact, it might even be easier. Here’s the equivalent of your code without jQuery:

    function setLocation(url) {
       if (window.location.href.indexOf(url) === -1)
          window.location = url;
    }
    
    function reloadPage(width) {
        if (width < 701) {
            setLocation("layout700.php");
        } else if (width < 900) {
            setLocation("layout900.php");
        } else {
            setLocation("layout1200.php");
        }
    }
    
    var done = false;
    
    function ready() {
        if(!done) {
            done = true;
            reloadPage(document.width);
        }
    }
    
    if(window.addEventListener) {
        window.addEventListener('DOMContentLoaded', ready, false);
        window.addEventListener('load', ready, false);
    } else if(window.attachEvent) {
        window.attachEvent('onload', ready);
    }
    
    window.onresize = function() {
        reloadPage(document.width);
    };
    

    However! You can also use media queries to restyle your page without making a fluid layout. This is better for a lot of reasons, most notably that your layout won’t depend on JavaScript and possibly sketchy compatibility. Here’s a good tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am currently using jQuery to load a variable php layout depending on
Currently I am using jQuery to choose what my index page should load depending
I'm currently using jQuery Cookies plugin, and depending on which side of the page
I am trying to load a part of the page using jQuery load function
I'm currently using Prototype, but I'd like to rewrite this function to jQuery: function
I'm currently using jquery's ajax feature or whatever they call it. To load data
I'm currently trying to build a filter search function using JQuery and Ajax. The
I'm currently loading a view(ascx) into a div using jQuery load(). I want to
Im using jquery to load in 2 external pages, one called search.php and the
I'm currently using jQuery to make a div clickable and in this div I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.