开发者社区 问答 正文

chrome 不能在onload的时候调用alert或confirm?

我有一个页面是这样写的

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>
function test()
{
    alert("testing.");    
}
</script>
</head>

<body onLoad="test();">

</body>
</html>

在用chrome调用时发现在alert窗口出来的时候有一个javascript错误

Uncaught TypeError: Cannot read property 'hasPort' of undefined
因为这个错误导致我后面的函数无法正常解析。
我想请问一下,这是chrome的错误还是我的函数错误?有没有办法解决?
我的chrome是16 beta和17 dev版的。

展开
收起
a123456678 2016-03-10 17:33:06 2443 分享 版权
1 条回答
写回答
取消 提交回答
  • 可以运行
    code如下:

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>New Web Project</title>
            <script type="text/javascript">
                function test(){
                    alert("ok?!");
                }
            </script>
        </head>
        <body onload="test();">
            
        </body>
    </html>
    2019-07-17 18:58:01
    赞同 展开评论