4

I have jQuery-2.1.4.min.js called before the tag, but when I write something like:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {
        alert('hi, world.');
    });
</script>

On my PC it is fired of course, but on ten different Android devices it just does not. This is purely HTML/CSS/jQuery rendered site (no phonegap, or anything).

My goal was to have a button do ajax request after it's being tapped, but I can't even test that, because the .ready() function is not firing at all on mobile chrome.

The jQuery is being served from the official CDN, any help would be very much appreciated.

Tried both:

$(function() {
   alert('hi, world.');
});

And

jQuery(document).ready(function() {
    alert('hi, world.');
});

Same thing.

As suggested I also tried:

window.onload = function()
{
    if (window.jQuery)
    {
        alert('jQuery is loaded');
    }
    else
    {
        alert('jQuery is not loaded');
    }
}

And it alerts 'jQuery is loaded'.

As per jQuery docs it says: "Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute" - which would mean that DOM is not ready for JavaScript code to execute? But when I try like:

<script type="text/javascript">
    alert('hi world');
</script>

It executes on mobile Chrome.

Dino
  • 401
  • 4
  • 17
  • How about trying `$` instead of `JQuery`, have you tried that? – Milan Chheda Jun 20 '17 at 18:03
  • Yes, I did. Tried "$" and "jQuery", same result. – Dino Jun 20 '17 at 18:23
  • Can you share how have you included/added JQuery? – Milan Chheda Jun 20 '17 at 18:26
  • Well if that was the problem why would it work on PC? Anyway here is how I included it: Above the actual – Dino Jun 20 '17 at 18:29
  • Example: this works: ``.. But this doesn't ``.. Also, if you notice, you need to add `//` in the `src`. – Milan Chheda Jun 20 '17 at 18:33
  • Yeah the https:// is there, it got parsed because of the comment. As I've said you have the OP updated. And if you see both my comment and updated OP I did close the – Dino Jun 20 '17 at 18:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/147193/discussion-between-milan-chheda-and-dino). – Milan Chheda Jun 20 '17 at 18:36

2 Answers2

8

Okay, after extensive investigation it seems that JS breaks on mobile chrome if you have document.ready() function twice, I had one in my core.js file and one in-line on the page.

It works okay on PC (all browsers), but on mobile it works up to the point of second ready() call and breaks all JS after that.

Hopefully this saves some time to others in the future.

Dino
  • 401
  • 4
  • 17
1

JS breaks on mobile view becouse same js use multiple time in file. Check and remove redundancy.

Tapeshwar
  • 71
  • 1
  • 2