Redirecting visitors based on window size

I have created three individual pages for screen resolutions of 1024, 768, and 320 width. Is there a method to automatically direct the visitor to the appropriate page based on their screen resolution?

The main reason I am not developing a responsive website is due to the Media Player included that does not adjust to the correct ratio.

Thank you in advance :) /Axel

Answer №1

Discover the height and width of the browser window using the Window.Screen object. Follow these steps:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">       
</script>‌​
<script type="text/javascript">
var width = screen.availWidth;
//Ensure width is an integer value for comparison
width = parseInt(width.toString());
var path='';
$(function(){
 if(width <= 320) 
 {
    path = "./320.html";
    loadWindow(path); 
  }
  else if (width > 320 && width <= 768) 
 {
   path = "./768.html";
   loadWindow(path); 
 }
 else if (width > 768 && width <= 1024) 
 {
   path = "./1024.html";
   loadWindow(path); 
  }
  else
  {
    path = "./1278.html";
    loadWindow(path); 
  }
});

//function to load the window
function loadWindow(path)
{ 
   window.location.href = path;
}
</script>
</head>

<body>
</body>
</html>

Answer №2

To create a webpage using JavaScript, you can use the following JavaScript code to retrieve the screen resolution of the user's device:

window.screen.availHeight
window.screen.availWidth

Based on this information, you can then direct the user to the appropriate radio station or page.

Answer №3

// Determine the width of the browser viewport
var windowWidth = $( window ).width();

// Load different pages based on the width of the viewport
if(windowWidth <= 320) {
$(document).load("./320.html");
}
else if (windowWidth > 320 && windowWidth <= 768) {
$(document).load("./768.html");
}
else if (windowWidth > 768 && windowWidth <= 1024) {
$(document).load("./1024.html");
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When access to Ajax .responseText in an alert it can be displayed, however it cannot be stored in a variable or

var response_var=""; // Added for debugging purposes ajax.onreadystatechange = function() { if (ajax.readyState == 4 & ajax.status == 200) { response_var = ajax.responseText; alert(ajax.responseText); // This alerts properly (some text ...

Is the original object cloned or passed by reference when passing it to a child React component through props?

When passing an object to a child component through the components props in React, does the object get cloned or does it simply pass a reference to the original object? For instance, in my App.js, I am importing a JSON object called ENTRY_DATA. Then, I pa ...

Issue with Bootstrap CSS: Default color change not functioning properly on Mobile devices, although it works correctly on Desktop

This is my first website project, you can check it out at www.craigdoesdata.de to see the issue I'm facing with CSS. I apologize if this question seems obvious or if it has already been addressed (I have spent a considerable amount of time searching f ...

When using Angular2, I have found that I am unable to extract the body data from JSONP responses. However, I have discovered that this issue

Initially, I developed the SERVER using spring-boot framework. The code for this looks like: public class App { @RequestMapping("/") @ResponseBody String home(HttpServletRequest request) { String aa=request.getParameter("callback"); System.out.pri ...

Avoiding a browser becoming frozen during an AJAX call

I'm currently working on sending a request when a user closes the page using the onbeforeunload event. This event triggers when the tab is closed or the page is refreshed. Here's my event implementation: window.onbeforeunload = function() { ...

What is the best way to extend an inline-block element to cover the entire text line?

Let's talk about the scenario: https://i.stack.imgur.com/we05U.png In the image, there is a container (displayed as a div) with only one child - a span element. The goal is to introduce a second child that occupies the entire red space depicted in t ...

Conceal Navigation with jQuery

Seeking assistance with jQuery for a new project. I'm trying to create a navigation menu that will automatically disappear after 3 seconds when a user enters the page. In its place, an arrow will be displayed instead of the original menu. Once the a ...

Adding points to vertices on mesh geometry based on their distance

My scene includes a THREE.Geometry with more than 5,000 vertices. I am looking to add THREE.Points to the scene for only 3 specific vertices of the mesh within the geometry. My goal is to achieve a similar outcome as shown in this example: https://i.sstat ...

Utilize Angular to dynamically assign values from object properties to an array of objects based on property names

In my array of objects, there is a property named "modulePermissions" inside an array of objects called "tabList". I have another object called "moduleName", which has the same value as the "modulePermissions" name, and a boolean value has been assigned to ...

The ActivatedRoute.routeConfig object appears to be empty in an Angular 2 project built with Angular-cli

Two projects I've created using angular-cli are working perfectly fine. However, in one of them, the routeConfig is showing as null and I can't figure out what's causing this issue. Both projects have identical package.json files, so there ...

Do package.json take precedence over lockfile in npm and yarn?

Let's say we're working with npm version 5.3.0+. Picture this scenario: I've just created a new package.json file in an empty directory and then ran npm i. Next, I went ahead and made some changes to the package versions in package.json. No ...

Can child elements be protected from deletion when their parent is set to contentEditable?

When a website element has the attribute contentEditable, its child elements can be removed. However, if one of those child elements is not set to be contentEditable, then the content within it cannot be edited but the entire element can still be deleted. ...

What steps can I take to fix error TS7015 in my TypeScript, Next.js, and React application when I encounter an index expression that is not a number data type?

I encountered an error stating "Element implicitly has an 'any' type because the index expression is not of type 'number'.ts(7015)" The file I imported is import { useAmazon } from "@context/amazon"; I used it as follows con ...

What is the best way to emphasize the selected color?

I am having trouble with setting the focus and active properties for an input element. Even after selecting a color, the highlight does not appear. However, the hover property is working fine. Here is the code I have used to implement the highlight proper ...

Several images displaying identical dimensions

I am in the process of creating a website for an exhibition but I am struggling with maintaining consistent dimensions for multiple photos without sacrificing quality. For reference, I would like my images to resemble those on this particular website: . B ...

Unusual phenomena exhibited by my variable scopes

I am a beginner in this industry and I have a desire to create an app. However, I am facing some challenges at the moment. Below is a simplified version of my code. My goal is to have the API display only the signUp option initially. Upon clicking on signU ...

How about switching from click-to-skip galleries to a sliding photo gallery?

Recently, I purchased a Joomla template from Template Monster. The template includes a photo gallery on the home page that requires users to click on the photos to navigate through them. However, what I really need is a self-sliding photo gallery that aut ...

What is the most efficient method for appending /.json to the conclusion of express routes?

I am currently transitioning a DJANGO API to Node.js and have been tasked with ensuring that routes support the .json extension at the end. For instance, sending a GET request to /users/:id/.json should return a JSON object representing the user. The cha ...

Changing the background color of tabs in Angular

Being a beginner in HTML and CSS, I recently utilized the angular-tabs-component to create tabs. Now, I am looking to change the background color of the tab. Can someone guide me on how to achieve this? Below is the code snippet: HTML: <tabs (currentT ...

Methods for smoothly animating an image to move up and down using CSS

I'm new to CSS and I was wondering if it's possible to create a smooth vertical movement effect for an image using CSS. Something like shown in this link: .... ...