简体   繁体   English

JavaScript 无法在移动 Safari 中工作

[英]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.好的,所以问题是我正在使用的 JS 代码将无法立即在移动 Safari 中运行。 Everything works fine in desktop safari, chrome, etc.在桌面 safari、chrome 等中一切正常。

In mobile safari (iphone 4 and ipod touch 2nd gen tested) the page is completely blank.在移动 safari(iphone 4 和 ipod touch 2nd gen 测试)中,页面完全空白。 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 http://osmithcouk.ipage.com/exposed/index.php

and here is JS code这是JS代码

NOTE I HAVE EDITED THE CODE SINCE RYUUTATSUO RECOMMENDED THAT I DO SO but still not working:(注意我已经编辑了代码,因为 RYUUTATSUO 建议我这样做但仍然无法正常工作:(

<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.这是与之相伴的 HTML。

<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 和show_hide 的CSS。

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

.show_hide {
    display:none;
}

Thank you very much for all your help:)非常感谢您的帮助:)

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.并且您还可以在您的 js 文件的注释中提供版本,以便客户可以知道他有最新版本的 JS 文件。

use利用

jQuery(window).load()

instead of代替

jQuery(document).ready()

I don't really know if this is the proper protocol but I have fixed it myself so thought I would post my answer!我真的不知道这是否是正确的协议,但我自己修复了它,所以我想我会发布我的答案!

It really is simple, I just moved the JS to below the.CSS.真的很简单,我只是把JS移到了.CSS下面。 Apparently Safari has a problem rendering jQuery before CSS:s显然 Safari 在 CSS 之前渲染 jQuery 时出现问题:s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM