javascript onload event does not firing on iphone - Stack Overflow

<body onload="javascript function"> is working well on desktop browser, but is not work

<body onload="javascript function"> is working well on desktop browser, but is not working on iPhone. My iPhone seems like it can read external CSS files and JS files, since when I click button from page, it fires JS functions. But oddly, only onload event is not working. I am so clueless now. Can anybody tell me why can't I fire onload event on iPhone? Below is my code.

<!DOCTYPE HTML>
<html>
    <head>
        <title>HTML5 연습</title>
        <meta name="viewport" content="width=480, user-scalable=1"/>
        <link rel="stylesheet" href="../styles/test1.css" />
        <script type="text/javascript" src="../scripts/fbsdk.js"></script>
        <script type="text/javascript" src="../scripts/initcss.js"></script>
        <script>
            //document.addEventListener('DOMContentLoaded', checkLoginCase, false);
        </script>
    </head>
    <body onload="checkLoginCase()">
        <div id="wrap">
            <header id="top">
                <img src="../fbimg/logo.png" alt="상단이미지" title="상단이미지">
            </header>
        </div>
        <button onclick="checkLoginCase()"> check fxn1</button>
        <button onclick="checkAlert()"> check fxn2</button>
    </body>
</html>

<body onload="javascript function"> is working well on desktop browser, but is not working on iPhone. My iPhone seems like it can read external CSS files and JS files, since when I click button from page, it fires JS functions. But oddly, only onload event is not working. I am so clueless now. Can anybody tell me why can't I fire onload event on iPhone? Below is my code.

<!DOCTYPE HTML>
<html>
    <head>
        <title>HTML5 연습</title>
        <meta name="viewport" content="width=480, user-scalable=1"/>
        <link rel="stylesheet" href="../styles/test1.css" />
        <script type="text/javascript" src="../scripts/fbsdk.js"></script>
        <script type="text/javascript" src="../scripts/initcss.js"></script>
        <script>
            //document.addEventListener('DOMContentLoaded', checkLoginCase, false);
        </script>
    </head>
    <body onload="checkLoginCase()">
        <div id="wrap">
            <header id="top">
                <img src="../fbimg/logo.png" alt="상단이미지" title="상단이미지">
            </header>
        </div>
        <button onclick="checkLoginCase()"> check fxn1</button>
        <button onclick="checkAlert()"> check fxn2</button>
    </body>
</html>
Share Improve this question edited Jun 7, 2012 at 6:05 Derek 朕會功夫 94.5k45 gold badges198 silver badges253 bronze badges asked Jun 7, 2012 at 6:02 Seho LeeSeho Lee 4,1089 gold badges34 silver badges42 bronze badges 3
  • let me check... my iOS version is 5.0.1 – Seho Lee Commented Jun 7, 2012 at 6:17
  • does your code also work using Safari on your desktop or if you access this page with the ipad's Safari (not in an UIWebView, with the ipad stand-alone browser)? – BBog Commented Jun 7, 2012 at 6:53
  • Turn on mobile safari developer mode (In Settings -> mobile safari) to see if any error found in the script. Script error may break the onload event. – vincicat Commented Jun 7, 2012 at 6:55
Add a ment  | 

1 Answer 1

Reset to default 2

It should be working, but try to avoid inline JavaScripts.

Try this:

window.onload = (function(){
    checkLoginCase();
});

//-or-

window.onload = checkLoginCase;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745493872a4630108.html

相关推荐

  • javascript onload event does not firing on iphone - Stack Overflow

    <body onload="javascript function"> is working well on desktop browser, but is not work

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信