Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript not working in Mobile Safari

Ok, so the problem is that JS code that I am using will not work in mobile Safari straight away. Everything works fine in desktop safari, chrome, etc.

In mobile safari (iphone 4 and ipod touch 2nd gen tested) the page is completely blank. BUT if you navigate to another page and then click back, it loads fine!

Could someone tell me what on earth is happening here?

Thanks :)

Here is a link to the site

http://osmithcouk.ipage.com/exposed/index.php

and here is JS code

NOTE I HAVE EDITED THE CODE SINCE RYUUTATSUO RECOMMENDED THAT I DO SO but still not working :(

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function(){

        $(".slidingDiv").hide();
        $(".show_hide").show();

    $('.show_hide').click(function(){
    $(".slidingDiv").slideToggle();
    });

});

And here is the HTML that goes alongside that.

<a href="#" class="show_hide"><b><?php include 'headline1.txt'; ?></b></a>
<div class="slidingDiv">
<?php include 'story1.txt'; ?> <a href="#" class="show_hide">Hide story...</a></div>

And the CSS for slidingDiv and show_hide.

.slidingDiv {
    background-color: #FFFFFF;
    padding:20px;
    margin-top:10px;
}

.show_hide {
    display:none;
}

Thank you very much for all your help :)

like image 822
Oliver Avatar asked Sep 14 '26 00:09

Oliver


1 Answers

Actually, the problem is that you have to add query string parameters in order to get it rendered on mobile. For example

script src="js/Common.js" type="text/javascript"

Should be replaced by

script src="js/Common.js?v=1.1" type="text/javascript"

and you can also supply version in comments of your js file so that client can come to know that he has latest version of JS files.

like image 116
Ikram Shah Avatar answered Sep 16 '26 15:09

Ikram Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!