The standard jQuery Mobile CSS styling does not seem to be working across various browsers, extensive testing has been conducted

I'm currently experimenting with jQuery Mobile to enhance my skills, but I'm facing issues with applying the basic CSS styling. I have included the css link from the jQuery Mobile website and ensured that I am connected to the internet. However, even after attempting to load the css locally into html, the styling still fails to apply.

Below is the code I have used for testing:

<!DOCTYPE html>
 
<html>
 
<head>
 
<meta charset="UTF-8">
 
<title>2test</title>
 
<meta name="viewport" content="width=device-width, initial-scale=1">
 
 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />

  <script src="http://code.jquery.com/jquery-1.4.5.min.js"></script> 
  <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
 
</head>


<body>

<div data-role="page">
<div id="header" data-role="header">
    <h1>My Photos</h1>
</div>

<article data-role="content">
    <ul data-role="listview" data-filter="true">
        <li>
            <a href="#">
            <h1>Miniature Doberman Pincher</h1>
            
            <p>This is what happens when a
            friend brings a dog to the studio.</p>
            </a>
        </li>
        <li>
            <a href="#">
            <h1>Gummy Bears</h1>
            
            <p>Three different poster boards...mirror for reflection,
            black for background white for highlights</p>
            </a>
        </li>
    </ul>


</article>

<footer data-role="footer" data-position="fixed">
    <nav data-role="navbar">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Photos</a></li>
            <li><a href="#">Info</a></li>
        </ul>
    </nav>
</footer>
</div>


</body>


</html>

Here is how the output appears on desktop Chrome 45 (EDIT: screenshot old, images since removed):

and this is the display on my android device Chrome 45 (accessed from hosted site):

Both outputs do not exhibit the expected mobile-friendly aesthetics of jQuery Mobile's default styling. What could possibly be missing in my implementation?

Answer №1

When checking the console, I noticed the following errors:

Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME http://code.jquery.com/jquery-1.4.5.min.js Failed to load resource: the     server responded with a status of 404 (Not Found) jquery.mobile-1.4.5.min.js:3 Uncaught TypeError: Cannot set property 'mobile' of undefined

It seems like JQM is struggling to parse local file paths, causing the JavaScript to fail. To resolve this issue, consider using relative paths instead of referencing local files.

Furthermore, it appears that some of your JQM paths may be incorrect:

<!-- add this link here -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- remove your link here -->
<!--  <script src="http://code.jquery.com/jquery-1.4.5.min.js></script> -->

Refer to jQuery Mobile getting started error for more information on including jQuery before JQM or utilizing a bundle.

In addition, there are other issues with your implementation. JQM manipulates DOM/HTML extensively and follows a structured approach different from other style frameworks. Reviewing the documentation would help in understanding JQM better.

According to

In jQuery Mobile, a page consists of an element with a data-role="page" attribute. Within the "page" container, valid HTML markup can be used, but typically includes divs with data-role="header", class="ui-content", and data-role="footer". The minimum requirement for a page is the page wrapper for navigation system support, everything else is optional.

Getting started with JQM can be tricky - make sure you have the required page div. It might be beneficial to start by copying examples and then customize as needed, ensuring to wrap content inside a page div for styling purposes.

<div data-role="page">
...
</div>

To see a working version of your example without images, visit http://jsfiddle.net/shotgundriver/8mb0rzhy/

Answer №2

While encountering the console error "Uncaught Security Error Failed to Execute Replace State on History..." in Chrome, I decided to search for solutions on Stack Overflow. It appears that Chrome's security features might be hindering the loading of content from an external source.

To troubleshoot, I attempted to load the page from a web server and interestingly, the CSS is successfully rendering in Chrome. Moreover, Firefox was able to render the page correctly when accessed locally. This issue seems to be specific to Chrome, preventing local testing.

For more information, you can refer to this Stack Overflow thread: Uncaught SecurityError: Failed to execute 'replaceState' on 'History': cannot be created in a document with origin 'null'

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

Ways to delete a div element according to its associated value

Check out this code snippet on jsFiddle: http://jsfiddle.net/fH3Sc/ If you want to remove the last occurrence of each special-text div without changing the provided HTML, you can use the following jQuery code: $(".special-text").slice(0, -1).remove(); T ...

Having trouble deleting multiple rows with ng-repeat in datatables

Having followed the instructions in this post, I quickly integrated it with jquery datatables. However, the functionality is not as expected. When attempting to delete rows, they do not get deleted. Furthermore, if I navigate to the next page and return, ...

show certain DIVs based on the URL

Is it possible to dynamically display different sections based on the URL? My event website has 3 subevents, and I'd like to show the date of each event in the navigation bar for their respective URLs. <div id="us" class="us-web-date">&nbs ...

What steps can I take to completely remove JavaScript from an HTML document?

To eliminate the <script> tags in the HTML, I can utilize regex just like this $html = preg_replace('#<script(.*?)>(.*?)</script>#is','', $html); While this approach works well, dealing with inline JavaScript require ...

What is the best way to define the width of text inside a div block?

I'm having trouble adjusting the width of the text in my code to only fill 80% of the body element. I've tried using both the width property and padding, but neither seems to be working for me at the moment. Here's the HTML: <body&g ...

Using Ajax to update table data in Rails

My index.html.erb file has a single view that showcases all employee names and details from the database. I have implemented a search form that should update the search results in the table tbody with id "content". Upon initial rendering, my index.html.erb ...

I'm looking to display images in a designated React component using create react app. What is the best way to accomplish

Currently in the process of revamping an older website using react. Making progress, but encountering an issue with a new component where images are not displaying. Strangely, the images appear in the main class but not within the component class. Even whe ...

Applying FAB (Material UI) to span across 2 columns in a CSS Grid: A step-by-step guide

Is there a way to make the zero button larger than the other buttons in its row by spanning 2 columns? I would like it to be an oversized oval shape. Appreciate any assistance you can provide. import "./styles.css"; import Button from '@mui/materia ...

Ensure that the Materialize CSS modal form remains open even after submission

Is there a way to reload a form inside a materialize modal with empty fields without closing the modal after submitting? The issue is that currently, when the submit button is clicked, the modal closes and redirects. <div class="modal" id="docM ...

Adding a subtle gradient to the image, just ahead of the SVG

Is there a way to achieve this particular look? https://i.stack.imgur.com/yQjvK.png I'm currently encountering this appearance issue. https://i.stack.imgur.com/eQjQ4.png Any suggestions on how I can make it match my desired outcome? Your assistan ...

How can I delete a video on mobile in WordPress?

Looking for some assistance with my webshop www.spidercatcher.dk. I'm trying to have a background video display only on PCs, while showing a still photo on phones and tablets. I've tried using a poster tag but I can't seem to scale it proper ...

I believe I am attempting to add some space to a row using CSS, or at least that's what I think I'm trying to achieve

Hey there, I need some help with adding an icon "services" section to my website. CSS is not my strongest suit, so I'm reaching out for assistance. My goal is to create blocks for the icons that don't touch the edge of the page and have a margin ...

Secret button concealed within a div, revealing only a helpful hint

On my website, there is a list of items where each item is represented by either a picture or a name enclosed in an <article> tag. Here is an example of how it looks: <article class="client-card"> <p><img width="211" height="106" ...

Tips for changing font styles using Polymer

I'm new to working with Polymer.js and CSS. My goal is to have text in todo.item display normally when todo.done is false, and with a line-through style when todo.done is true. I'm considering using CSS for this task, but I'm unsure how to ...

Using Column CSS Property with Google Maps in Chrome: A Potential Bug?

I'm facing an interesting issue and I could use some help understanding or fixing it. It seems like there might be a bug or a solution to this problem. I am currently working on a layout using the CSS3 property columns. Everything looks fine in Firefo ...

Fixed position not being maintained after clicking the button

Looking for some help with a fixed header issue on my website. The header is supposed to stay at the top while scrolling, which works well. However, when I switch to responsive view, click the menu button, and then go back to desktop view, none of the po ...

Using jQuery mobile with MVC4 - implement a loading image to display when navigating to a new page either through a link click or postback

While jQuery mobile provides a nice page loading animation, it can still result in a brief moment where the user sees a 'white' page before the new content is displayed. To address this issue, I have implemented the following code: $.mobile.load ...

Firing the event after using jQuery to bind the event

When I call the function below, it binds another function to the onClick event. The interesting part is that invoking this first function triggers the execution of the second function. Note that the LinkName parameter in the initial function refers to a ...

Multiple Ajax calls interacting with each other are causing issues

Within my Index.php file, there is an ajax call that loads a php page containing an HTML form. I am attempting to trigger another ajax call from Index.php whenever a select box is changed. Everything functions properly except for the ajax on change event ...

JavaScript event listener 'click' not functioning properly

I'm facing an issue with a click event in a script that is associated with a specific div id. When I move the mouse within the div area and click (the cursor remains unchanged), the event listener does not activate. How can I make the div area clickab ...