【发布时间】:2011-01-24 20:45:24
【问题描述】:
我有一个包含大量图像和其他代码的页面,如果延迟加载会更好。
我一直在尝试使用 noscript 标记来执行此操作,但我只是注意到它在 IE 中无法正常工作。它适用于我测试过的所有其他浏览器(ff、opera、chrome、safari 等),所以我有点沮丧。
我很确定在某一时刻我实际上已经在 IE 中工作过,因为我已经使用该技术有一段时间了,而且我经常测试 IE...但它现在不起作用,我用谷歌搜索的所有内容似乎表明它从未起作用。
这是一个简单的复制和粘贴示例,显示了我正在尝试的内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>lazy load with noscript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<noscript>
<div>
<p>other content here</p>
<img src="http://www.google.com/images/logos/ps_logo.png" alt="lazy loading image test" />
</div>
</noscript>
<noscript>
<div>
<p>other content here 2</p>
<img src="http://www.google.com/images/logos/ps_logo2.png" alt="lazy loading image test 2" />
</div>
</noscript>
<script type="text/javascript">
var html = $("noscript:first").text();
alert(html);
$("body").append(html);
</script>
</body>
</html>
使用 javascript 和没有 javascript 的用户使用的 html 是相同的。我只是使用 jquery 来标记内容以使其更易于查看。由于内容在 javascript 中以标签形式显示,因此在打开标签时需要延迟加载,因此当页面具有相当大的附件时,最初下载不会花费很长时间。
如何在不多次输出 html 的情况下实现这一点?
【问题讨论】:
-
如果启用脚本,IE 似乎不会向 dom 添加 noscript 标签。见:tjs.co.uk/blog/…
标签: javascript jquery html graceful-degradation noscript