大网数据广告活动
Web 标准与前端开发

HTMLLinkElement: imageSrcset property

· 52CE 我爱测

The **`imageSrcset`** property of the HTMLLinkElement interface is a string which identifies one or more comma-separated **image candidate strings**. This property reflects the value of the link element's `imagesrcset` attribute. This property can retrieve or set the `imagesrcset

HTML DOM

The imageSrcset property of the HTMLLinkElement interface is a string which identifies one or more comma-separated image candidate strings. This property reflects the value of the link element's imagesrcset attribute. This property can retrieve or set the imagesrcset attribute value.

Each image candidate string contains an image URL and an optional width and/or pixel density descriptor indicating the conditions under which that candidate image should be used.

"images/team-photo.jpg, images/team-photo-retina.jpg 2x, images/team-photo-large.jpg 1400w"

For HTML link elements with rel="preload" and as="image" set, the imagesrcset attribute has similar syntax and semantics as the img element's srcset attribute, which indicates to preload the appropriate resource used by an <img> element with corresponding values for its srcset and sizes attributes.

If the imageSrcset property includes width descriptors, the HTMLLinkElement.imageSizes property must be non-null, or the imageSrcset value will be ignored.

Value

A string composed of a comma-separated list of one or more image candidate strings, or the empty string "" if unspecified.

Examples

Given the following <link> element:

<link
  rel="preload"
  as="image"
  imagesizes="50vw"
  imagesrcset="bg-narrow.png, bg-wide.png 800w" />
<pre id="log"></pre>
#log {
  padding: 0 0.25rem;
  font-size: 1.2em;
  line-height: 1.4;
}
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}

…we can access the imagesrcset attribute value, and update it, using the imageSrcset property:

const link = document.querySelector("link");
log(`Original: ${link.imageSrcset}`);

// add an image candidate string
link.imageSrcset += ", bg-huge.png 1200w";
log(`Updated: ${link.imageSrcset}`);

Examples

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。