以下代碼僅適用於Chrome。我需要它在所有主流瀏覽器上運行。 Firefox和IE加載圖像一次。 Opera根本不加載它。如何使此JavaScript代碼便攜?
screen.jpg文件與Cache-Control: no-cache, no-store
一起發送。我不能使用像jQuery這樣的庫,因爲它們太大了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function refresh()
{
document.getElementById("screen").src = "screen.jpg";
setTimeout("refresh()", 500);
}
</script>
</head>
<body style="margin:0" onload="refresh()">
<img id="screen" style="width:100%"/>
</body>
</html>
jQuery的minified的是30KB。那真的是「太大」了嗎? – darioo 2012-01-02 13:56:03
也許不是太大,但在2分鐘內太大瞭解 – rene 2012-01-02 13:58:33
argh - setTimeout的字符串參數!它應該是'setTimeout(refresh,500)'。 – Alnitak 2012-01-02 13:59:15