Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

HTMLScriptElement: src property

BaselineWidely available *

Thesrc property of theHTMLScriptElement interface is a string representing the URL of an external script; this can be used as an alternative to embedding a script directly within a document.

It reflects thesrc attribute of the<script> element.

Value

A string.

Examples

Assume the code is running on a website whose URL ishttps://example.com.

html
<script type="module" src="/main.js"></script><script type="module"></script>
js
const script_with_src = document.getElementById("script-with-src");console.log(script_with_src.src); // Output: "https://example.com/main.js"const script_without_src = document.getElementById("script-without-src");console.log(script_without_src.src); // Output: ""

Specifications

Specification
HTML
# dom-script-src

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp