我写了这个JS:
var prefetchUrls = function () {
var prefetchElements = document.getElementsByClassName('prefetch');
for (var i = 0; i < prefetchElements.length; i++) {
(function () {
var el = i;
prefetchElements[i].addEventListener('mouseover',
function (e) {
prefetchTimeout = setTimeout(function () {
if (document.getElementById('prefetch-' + el) == null) {
var url = e.target.getAttribute('href');
var link = document.createElement('link');
link.setAttribute('rel', 'prefetch');
link.setAttribute('href', url);
link.id = 'prefetch-' + el;
document.getElementsByTagName('head')[0].appendChild(link);
}
}(el), 200);
});
prefetchElements[i].addEventListener('mouseleave', function () {
clearTimeout(prefetchTimeout);
});
}());
}
}
prefetchUrls();
HTML:
<a href="/echo/json/" class="prefetch">Test 1</a>
<a href="/echo/html/">Test 2</a>
<a href="/echo/xml/" class="prefetch">Test 3</a>
我的脚本在鼠标悬停时<head>
创建一个预取链接标记(在200毫秒之后),对于带有&#34;预取&#34;的元素类。到目前为止在Chrome中运行正常,但是虽然network.dns.disablePrefetch
被禁用(false)并且network.prefetch-next
已启用(true),但Firefox网络面板中没有活动。任何提示?