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 6994823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:56:29+00:00 2026-05-27T19:56:29+00:00

Hello friends a very novice question as I am very new to programming. I

  • 0

Hello friends a very novice question as I am very new to programming.

I was browsing the web and found a method to dynamically load a CSS file based on the browser width.

jQuery

function adjustStyle(width) {
    width = parseInt(width);
    if (width < 701) {
        $("#size-stylesheet").attr("href", "css/narrow.css");
    } else if ((width >= 701) && (width < 900)) {
        $("#size-stylesheet").attr("href", "css/medium.css");
    } else {
       $("#size-stylesheet").attr("href", "css/wide.css"); 
    }
}

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

HTML

<link rel="stylesheet" type="text/css" href="main.css" />
<link id="size-stylesheet" rel="stylesheet" type="text/css" href="narrow.css" />

I want to know, can I use the same to load a php file?

If yes what will be the code look like?

I think we will be required to use something like <?php require_once('http://mysite.com/layouts/ipad.php'); ?> but how do I code it?

Kindly help.

Regards

  • 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-05-27T19:56:29+00:00Added an answer on May 27, 2026 at 7:56 pm

    I want to know, can I use the same to load a php file?

    If by “load a php file” you mean load a different page where you’ll define different pages for different conditions (widths, whatever), then you can load different pages by setting window.location equal to the desired page. This will replace the current page with the one you specify.

    I don’t think you should do this every time the window is resized though. If you must do it at least check whether the new size actually requires a change rather than repeatedly reloading it regardless.

    Following is similar to your existing code:

    function setLocation(url) {
       if (window.location.href.indexOf(url) === -1)
          window.location = url;
    }
    
    function reloadPage(width) {
        width = parseInt(width);
        if (width < 701) {
            setLocation("yournarrowpage.php");
        } else if (width < 900) {
            setLocation("yourmediumpage.php");
        } else {
            setLocation("yourwidepage.php");
        }
    }
    
    $(function() {
       reloadPage($(this).width());
       $(window).resize(function() {
           reloadPage($(this).width());
       });
    });
    

    You don’t have to reload the entire page each time though, you can reload just certain sections using ajax. For that you could do something similar to the above except instead of setting window.location you’d use jQuery’s .load() method:

    function setLocation(url) {
       $("selector for the element to reload").load(url);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Friends check my code http://jsfiddle.net/sUaky/2/ i want to load a web page in
Hello friends it may sound awkward but i am novice to asp dotnet web
Hello Friends I am a newbie programmer and very very new to PHP. I
Hello friends I am coming here with a confusion I found a web page
Hello friends i am very new to ios. I am setting scroll size in
hello friends i m new to jQuery and nyro modal. right now i m
Hello Friends i have the following query which defeat the very purpose. A day
hello friends I need to download mp3 file from the internet and to store
Hello friends i want to show Ajax loader before Data load in particular div
Hello friends i am to add optional parameter to pass these in a method

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.