Is there a way to determine if a user is using a mobile device and automatically direct them to a mobile-friendly website?

Currently, I am managing 2 websites and I would like to implement an automatic redirection for mobile users.

Despite my efforts in researching various websites and viewing tutorials, I have not been successful in making it work.

My intention is to redirect mobile users to the mobile version of the site while keeping PC/Mac users on the regular site.

Answer №1

You have the option to employ basic javascript.

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ) {
 //execute this code for mobile devices
}

Answer №2

Verify whether the Screen Size is less than 699.

<script type="text/javascript">
    if (screen.width <= 699) {
        document.location = "mobile.html";
    }
</script>

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

wrap text image not compatible with responsive layout

Plunker Link: https://plnkr.co/edit/kC9SPK2e7iy5OYhKpwOO?p=preview <html> <head> <link data-require="bootstrap@*" data-semver="4.1.3" rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" /> ...

JavaScript and jQuery experiencing difficulty rendering proper style and image in output display

I am currently working on code that extracts information from a JSON variable and displays it on a map. The code looks like this: marker.info_window_content = place.image + '<br/>' +"<h4>" + place.name + "</h4> ...

Is there a method for redirecting my page to a specific href link without triggering a page reload?

This is my HTML code. <a href="http://127.1.1.0:8001/gembead/emstones.html?car=36">Car</a> I am trying to redirect to a specific page with parameters without fully reloading the current page. Is there a way to achieve this task? I believe the ...

Issue with the initial element in CSS and the cause remains a mystery

"first of type" dont like to work: .elements { width:70%; margin:0 auto; display:flex; flex-direction: column; .addElement { width:280px; text-align: center; border:1px solid black; font-family: ...

Difficulties encountered when preserving the data of a website in HTML format

Usually, I request tweets on Twitter for a specific period and then scroll down the page to the last tweet. I save the HTML code of this page by right-clicking and selecting "Save As..." However, only the latest tweets are displayed in this HTML file. Is ...

Issue with ngShow not functioning when used within an HTML template

I'm struggling with displaying and hiding a div from a template on an HTML page. You can see a simple JSFiddle example here. app.directive('example', function () { return { restrict: 'E', template: '< ...

JavaScript threw an error with message: 'Unexpected identifier' that was not caught

Upon launching Web Developer in Firefox: SyntaxError: missing } after property list note: { was opened at line 7, column 7 ...

problems arising from the alignment of floating divs

I am struggling with aligning the image "logo.jpg" in a left-floated div. How can I center it both vertically and horizontally within the code below? Thank you. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm ...

How to dynamically insert a new row below a specific row with a sliding animation in jQuery

My task is to create a tree-like table structure where clicking on a specific row will reveal and add new rows below it. Specifically, I am designing the Category and SubCategory structure. Currently, I can append rows after a specified row but am struggl ...

Cross-Browser Compatibility of CSS

I have noticed that lists styled with the following CSS code appear differently in Internet Explorer 8 and Firefox 4. In IE8, the rounded corners are missing, while FF4 does not change color when hovering over it. Which browser should I trust for accurate ...

The php code managed to infect my website

My website has been infected by a plugin that is generating ads for a company I am not affiliated with. I tried using anti-malware software, but it didn't detect anything. var doc = document.getElementById('ad_iframe').contentWindow.document ...

Understanding how to activate a React navbar button is essential for creating a seamless user

How can I make my sidebar button change color when I navigate to the page it links to? ...

What is the best way to collapse the entire navigation menu after clicking a link (nav-link) within it?

I created a navigation menu using HTML and SCSS, but I'm facing an issue where the menu does not close when clicking on links inside it. The menu continues to overlay the content on the page instead of closing. Essentially, I want the navigation menu ...

What is the best way to make sure that every line break in HTML appears as a break line in the browser?

When working with HTML and its companion CSS, it is important to... Exploring HTML: <html> <head> <link href="css/breakLineInBrowser.css" rel="stylesheet"> </head> <body> <p> Line 1. Line 2. Lin ...

What is the best way to dynamically resize row height in Bootstrap?

Currently, I'm delving into Bootstrap and facing a challenge of automatically adjusting row heights under specific conditions: In a container-fluid, there are 3 rows Row1 should accommodate the height of its content Row3 needs to adjust to its conte ...

Troubles with element alignment

Hello everyone, I am in need of some assistance with HTML and CSS. I am a complete beginner and I am trying to create a design that looks like the one shown below: While I have managed to generate the container itself, I am having trouble with aligning ...

Divide the text array into pages within an HTML textarea using a loop

I am trying to implement pagination for an array where users can navigate using previous and next buttons or by specifying a position. When the index changes, I want the corresponding value to be displayed. Although I have attempted to achieve this with t ...

Press here to unveil and modify using the Redactor JS WYSIWYG HTML editor

I am working on a project where I have three separate divs that are set to be editable using the attribute contenteditable="true". Additionally, I have configured the redactor wysiwyg toolbar to remain fixed on the page. Here is the structure in HTML: &l ...

Activating Vue-Bootstrap components through an image click event in VueJS 2

Seeking to achieve: VueJS integration with Bootstrap for clickable cards I am currently working on a VueJS project where I want the cards to be clickable and reveal collapsible elements upon click. To accomplish this, I have implemented a button with the ...

jQuery width property does not seem to be functional on menus that do not contain any dropdown

I am currently working on creating a menu that displays arrows underneath the items when hovered over or when the .active class is added to the menu. Everything is working fine, except for the fact that it only works on menus with drop-downs and the child ...