I have jQuery-2.1.4.min.js called before the tag, but when I write something like:
<script type="text/javascript" src=".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.
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./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.
Share Improve this question edited Jun 20, 2017 at 19:22 Dino asked Jun 20, 2017 at 17:45 DinoDino 4025 silver badges17 bronze badges 7-
How about trying
$
instead ofJQuery
, have you tried that? – Milan Chheda Commented Jun 20, 2017 at 18:03 - Yes, I did. Tried "$" and "jQuery", same result. – Dino Commented Jun 20, 2017 at 18:23
- Can you share how have you included/added JQuery? – Milan Chheda Commented Jun 20, 2017 at 18:26
- Well if that was the problem why would it work on PC? Anyway here is how I included it: <script src="code.jquery./jquery-2.2.4.min.js"></script> Above the actual <script> tag containing .ready() function (as described in the OP). OP updated. – Dino Commented Jun 20, 2017 at 18:29
-
Example: this works:
<script type="text/javascript" src="//ajax.googleapis./ajax/libs/jquery/2.2.4/jquery.js"></script>
.. But this doesn't<script type="text/javascript" src="//ajax.googleapis./ajax/libs/jquery/2.2.4/jquery.js"/>
.. Also, if you notice, you need to add//
in thesrc
. – Milan Chheda Commented Jun 20, 2017 at 18:33
2 Answers
Reset to default 8Okay, 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.
JS breaks on mobile view becouse same js use multiple time in file. Check and remove redundancy.