搜索

首页  >  问答  >  正文

javascript - 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版的。

迷茫迷茫2894 天前818

全部回复(3)我来回复

  • PHPz

    PHPz2017-04-10 12:43:37

    可以运行
    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>

    回复
    0
  • 巴扎黑

    巴扎黑2017-04-10 12:43:37

    正常,可以运行
    版本 17.0.942.0

    回复
    0
  • 怪我咯

    怪我咯2017-04-10 12:43:37

    如果你的页面是 background 页面,那这样应该是弹不出来的,如果是 popup 或者是 options 页面 ,应该没有什么问题。

    如果依然有问题,可以向 chrome 提交 issue.

    回复
    0
  • 取消回复